+#define SOURCE_STRING L"Hello"\r
+\r
+STATIC\r
+UNIT_TEST_STATUS\r
+EFIAPI\r
+SafeStringContraintCheckTest (\r
+ IN UNIT_TEST_CONTEXT Context\r
+ )\r
+{\r
+ RETURN_STATUS Status;\r
+ CHAR16 Destination[20];\r
+ CHAR16 AllZero[20];\r
+\r
+ //\r
+ // Zero buffer used to verify Destination is not modified\r
+ //\r
+ ZeroMem (AllZero, sizeof (AllZero));\r
+\r
+ //\r
+ // Positive test case copy source unicode string to destination\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR16), SOURCE_STRING);\r
+ UT_ASSERT_NOT_EFI_ERROR (Status);\r
+ UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, sizeof (SOURCE_STRING));\r
+\r
+ //\r
+ // Positive test case with DestMax the same as Source size\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, sizeof (SOURCE_STRING) / sizeof (CHAR16), SOURCE_STRING);\r
+ UT_ASSERT_NOT_EFI_ERROR (Status);\r
+ UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, sizeof (SOURCE_STRING));\r
+\r
+ //\r
+ // Negative test case with Destination NULL\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (NULL, sizeof (Destination) / sizeof (CHAR16), SOURCE_STRING);\r
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
+ UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
+\r
+ //\r
+ // Negative test case with Source NULL\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR16), NULL);\r
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
+ UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
+\r
+ //\r
+ // Negative test case with DestMax too big\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, MAX_UINTN, SOURCE_STRING);\r
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
+ UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
+\r
+ //\r
+ // Negative test case with DestMax 0\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, 0, SOURCE_STRING);\r
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
+ UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
+\r
+ //\r
+ // Negative test case with DestMax smaller than Source size\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, 1, SOURCE_STRING);\r
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_BUFFER_TOO_SMALL);\r
+ UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
+\r
+ //\r
+ // Negative test case with DestMax smaller than Source size by one character\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, sizeof (SOURCE_STRING) / sizeof (CHAR16) - 1, SOURCE_STRING);\r
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_BUFFER_TOO_SMALL);\r
+ UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
+\r
+ //\r
+ // Negative test case with overlapping Destination and Source\r
+ //\r
+ ZeroMem (Destination, sizeof (Destination));\r
+ Status = StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR16), Destination);\r
+ UT_ASSERT_STATUS_EQUAL (Status, RETURN_ACCESS_DENIED);\r
+ UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
+\r
+ return UNIT_TEST_PASSED;\r
+}\r
+\r