Changeset 27968 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Apr 2, 2010 8:36:35 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 59674
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTGetOptArgv.cpp
r27797 r27968 49 49 const char * const apszArgs[5]; 50 50 const char *pszCmdLine; 51 } s_a Tests[] =51 } s_aMscCrtTests[] = 52 52 { 53 53 { … … 69 69 }; 70 70 71 for (size_t i = 0; i < RT_ELEMENTS(s_a Tests); i++)71 for (size_t i = 0; i < RT_ELEMENTS(s_aMscCrtTests); i++) 72 72 { 73 73 char *pszCmdLine = NULL; 74 int rc = RTGetOptArgvToString(&pszCmdLine, s_a Tests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);75 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 76 if (strcmp(s_a Tests[i].pszCmdLine, pszCmdLine))74 int rc = RTGetOptArgvToString(&pszCmdLine, s_aMscCrtTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 75 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 76 if (strcmp(s_aMscCrtTests[i].pszCmdLine, pszCmdLine)) 77 77 RTTestIFailed("g_aTest[%i] failed:\n" 78 78 " got '%s'\n" 79 79 " expected '%s'\n", 80 i, pszCmdLine, s_aTests[i].pszCmdLine); 80 i, pszCmdLine, s_aMscCrtTests[i].pszCmdLine); 81 RTStrFree(pszCmdLine); 82 } 83 84 85 RTTestISub("RTGetOptArgvToString / BOURNE_SH"); 86 87 static const struct 88 { 89 const char * const apszArgs[5]; 90 const char *pszCmdLine; 91 } s_aBournShTests[] = 92 { 93 { 94 { "abcd", "a ", " b", " c ", NULL }, 95 "abcd 'a ' ' b' ' c '" 96 }, 97 { 98 { "a\n\\b", "de'fg", "h", "'", NULL }, 99 "'a\n\\b' 'de'\"'\"'fg' h ''\"'\"''" 100 } 101 }; 102 103 for (size_t i = 0; i < RT_ELEMENTS(s_aBournShTests); i++) 104 { 105 char *pszCmdLine = NULL; 106 int rc = RTGetOptArgvToString(&pszCmdLine, s_aBournShTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); 107 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 108 if (strcmp(s_aBournShTests[i].pszCmdLine, pszCmdLine)) 109 RTTestIFailed("g_aTest[%i] failed:\n" 110 " got |%s|\n" 111 " expected |%s|\n", 112 i, pszCmdLine, s_aBournShTests[i].pszCmdLine); 113 RTStrFree(pszCmdLine); 114 } 115 116 117 RTTestISub("RTGetOptArgvToString <-> RTGetOptArgvFromString"); 118 119 for (size_t i = 0; i < RT_ELEMENTS(s_aBournShTests); i++) 120 { 121 char *pszCmdLine = NULL; 122 int rc = RTGetOptArgvToString(&pszCmdLine, s_aBournShTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); 123 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 124 125 char **papszArgs; 126 int cArgs; 127 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, NULL); 128 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 129 130 size_t j = 0; 131 while (papszArgs[j] && s_aBournShTests[i].apszArgs[j]) 132 { 133 if (strcmp(papszArgs[j], s_aBournShTests[i].apszArgs[j])) 134 RTTestIFailed("Test #%u, argument #%u mismatch:\n" 135 " FromString: |%s| (got)\n" 136 " ToString: |%s| (expected)\n", 137 i, j, papszArgs[j], s_aBournShTests[i].apszArgs[j]); 138 139 /* next */ 140 j++; 141 } 142 RTTESTI_CHECK(papszArgs[j] == NULL); 143 RTTESTI_CHECK(s_aBournShTests[i].apszArgs[j] == NULL); 144 145 RTGetOptArgvFree(papszArgs); 81 146 RTStrFree(pszCmdLine); 82 147 }
Note:
See TracChangeset
for help on using the changeset viewer.