Changeset 36375 in vbox for trunk/src/VBox/HostServices/GuestProperties/testcase/tstGuestPropSvc.cpp
- Timestamp:
- Mar 23, 2011 5:00:53 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/GuestProperties/testcase/tstGuestPropSvc.cpp
r36259 r36375 23 23 #include <iprt/initterm.h> 24 24 #include <iprt/stream.h> 25 #include <iprt/test.h> 26 27 /******************************************************************************* 28 * Global Variables * 29 *******************************************************************************/ 30 static RTTEST g_hTest = NIL_RTTEST; 25 31 26 32 using namespace guestProp; … … 66 72 const char *pcszOut; 67 73 } 68 validFlagStrings[] = 69 { 70 { " ", "" }, 71 { "transient, ", "TRANSIENT" }, 72 { " rdOnLyHOST, transIENT , READONLY ", "TRANSIENT, READONLY" }, 73 { " rdonlyguest", "RDONLYGUEST" }, 74 { "rdonlyhost ", "RDONLYHOST" }, 75 { "transient, transreset, rdonlyhost", 76 "TRANSIENT, RDONLYHOST, TRANSRESET" } 74 g_validFlagStrings[] = 75 { 76 /* pcszIn, pcszOut */ 77 { " ", "" }, 78 { "transient, ", "TRANSIENT" }, 79 { " rdOnLyHOST, transIENT , READONLY ", "TRANSIENT, READONLY" }, 80 { " rdonlyguest", "RDONLYGUEST" }, 81 { "rdonlyhost ", "RDONLYHOST" }, 82 { "transient, transreset, rdonlyhost", "TRANSIENT, RDONLYHOST, TRANSRESET" }, 83 { "transient, transreset, rdonlyguest", "TRANSIENT, RDONLYGUEST, TRANSRESET" }, 84 { "rdonlyguest, rdonlyhost", "READONLY" } 77 85 }; 78 86 … … 81 89 * functions should reject these. 82 90 */ 83 const char * invalidFlagStrings[] =91 const char *g_invalidFlagStrings[] = 84 92 { 85 93 "RDONLYHOST,,", … … 95 103 { 96 104 int rc = VINF_SUCCESS; 105 char *pszFlagBuffer = (char *)RTTestGuardedAllocTail(g_hTest, MAX_FLAGS_LEN); 106 97 107 RTPrintf("tstGuestPropSvc: Testing conversion of valid flags strings.\n"); 98 for (unsigned i = 0; i < RT_ELEMENTS(validFlagStrings) && RT_SUCCESS(rc); ++i) 99 { 100 char szFlagBuffer[MAX_FLAGS_LEN * 2]; 108 for (unsigned i = 0; i < RT_ELEMENTS(g_validFlagStrings) && RT_SUCCESS(rc); ++i) 109 { 101 110 uint32_t fFlags; 102 rc = validateFlags( validFlagStrings[i].pcszIn, &fFlags);111 rc = validateFlags(g_validFlagStrings[i].pcszIn, &fFlags); 103 112 if (RT_FAILURE(rc)) 104 RTPrintf("tstGuestPropSvc: FAILURE - Failed to validate flag string '%s'.\n", validFlagStrings[i].pcszIn);113 RTPrintf("tstGuestPropSvc: FAILURE - Failed to validate flag string '%s'.\n", g_validFlagStrings[i].pcszIn); 105 114 if (RT_SUCCESS(rc)) 106 115 { 107 rc = writeFlags(fFlags, szFlagBuffer);116 rc = writeFlags(fFlags, pszFlagBuffer); 108 117 if (RT_FAILURE(rc)) 109 118 RTPrintf("tstGuestPropSvc: FAILURE - Failed to convert flag string '%s' back to a string.\n", 110 111 } 112 if (RT_SUCCESS(rc) && (strlen( szFlagBuffer) > MAX_FLAGS_LEN - 1))119 g_validFlagStrings[i].pcszIn); 120 } 121 if (RT_SUCCESS(rc) && (strlen(pszFlagBuffer) > MAX_FLAGS_LEN - 1)) 113 122 { 114 123 RTPrintf("tstGuestPropSvc: FAILURE - String '%s' converts back to a flag string which is too long.\n", 115 124 g_validFlagStrings[i].pcszIn); 116 125 rc = VERR_TOO_MUCH_DATA; 117 126 } 118 if (RT_SUCCESS(rc) && (strcmp( szFlagBuffer,validFlagStrings[i].pcszOut) != 0))127 if (RT_SUCCESS(rc) && (strcmp(pszFlagBuffer, g_validFlagStrings[i].pcszOut) != 0)) 119 128 { 120 129 RTPrintf("tstGuestPropSvc: FAILURE - String '%s' converts back to '%s' instead of to '%s'\n", 121 validFlagStrings[i].pcszIn,szFlagBuffer,122 130 g_validFlagStrings[i].pcszIn, pszFlagBuffer, 131 g_validFlagStrings[i].pcszOut); 123 132 rc = VERR_PARSE_ERROR; 124 133 } … … 127 136 { 128 137 RTPrintf("Testing rejection of invalid flags strings.\n"); 129 for (unsigned i = 0; i < RT_ELEMENTS( invalidFlagStrings) && RT_SUCCESS(rc); ++i)138 for (unsigned i = 0; i < RT_ELEMENTS(g_invalidFlagStrings) && RT_SUCCESS(rc); ++i) 130 139 { 131 140 uint32_t fFlags; 132 141 /* This is required to fail. */ 133 if (RT_SUCCESS(validateFlags( invalidFlagStrings[i], &fFlags)))142 if (RT_SUCCESS(validateFlags(g_invalidFlagStrings[i], &fFlags))) 134 143 { 135 144 RTPrintf("String '%s' was incorrectly accepted as a valid flag string.\n", 136 invalidFlagStrings[i]);145 g_invalidFlagStrings[i]); 137 146 rc = VERR_PARSE_ERROR; 138 147 } … … 141 150 if (RT_SUCCESS(rc)) 142 151 { 143 char szFlagBuffer[MAX_FLAGS_LEN * 2];144 152 uint32_t u32BadFlags = ALLFLAGS << 1; 145 153 RTPrintf("Testing rejection of an invalid flags field.\n"); 146 154 /* This is required to fail. */ 147 if (RT_SUCCESS(writeFlags(u32BadFlags, szFlagBuffer)))155 if (RT_SUCCESS(writeFlags(u32BadFlags, pszFlagBuffer))) 148 156 { 149 157 RTPrintf("Flags 0x%x were incorrectly written out as '%.*s'\n", 150 u32BadFlags, MAX_FLAGS_LEN, szFlagBuffer);158 u32BadFlags, MAX_FLAGS_LEN, pszFlagBuffer); 151 159 rc = VERR_PARSE_ERROR; 152 160 } 153 161 } 162 163 RTTestGuardedFree(g_hTest, pszFlagBuffer); 154 164 return rc; 155 165 } … … 1040 1050 int main(int argc, char **argv) 1041 1051 { 1042 VBOXHGCMSVCFNTABLE svcTable; 1043 VBOXHGCMSVCHELPERS svcHelpers; 1044 1052 VBOXHGCMSVCFNTABLE svcTable; 1053 VBOXHGCMSVCHELPERS svcHelpers; 1054 RTEXITCODE rcExit; 1055 1056 rcExit = RTTestInitAndCreate("tstGuestPropSvc", &g_hTest); 1057 if (rcExit != RTEXITCODE_SUCCESS) 1058 return rcExit; 1059 RTTestBanner(g_hTest); 1060 1061 /** @todo convert the rest of this testcase. */ 1045 1062 initTable(&svcTable, &svcHelpers); 1046 RTR3Init(); 1063 1047 1064 if (RT_FAILURE(testConvertFlags())) 1048 1065 return 1; … … 1081 1098 if (RT_FAILURE(testDelPropROGuest(&svcTable))) 1082 1099 return 1; 1083 RTPrintf("tstGuestPropSvc: SUCCEEDED.\n"); 1084 return 0;1085 } 1100 1101 return RTTestSummaryAndDestroy(g_hTest); 1102 }
Note:
See TracChangeset
for help on using the changeset viewer.