vbox的更動 17141 路徑 trunk/src/VBox/Runtime/testcase
- 時間撮記:
- 2009-2-25 下午05:09:22 (16 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/testcase/tstGetOpt.cpp
r17100 r17141 41 41 int cErrors = 0; 42 42 RTR3Init(); 43 RTPrintf("tstGetOpt: TESTING...\n"); 43 44 44 45 RTGETOPTSTATE GetState; 45 46 RTGETOPTUNION Val; 46 47 #define CHECK(expr) do { if (!(expr)) { RTPrintf("tstGetOpt: error line %d (iNext=%d): %s\n", __LINE__, GetState.iNext, #expr); cErrors++; } } while (0) 48 #define CHECK2(expr, fmt) \ 49 do { \ 50 if (!(expr)) { \ 51 RTPrintf("tstGetOpt: error line %d (iNext=%d): %s\n", __LINE__, GetState.iNext, #expr); \ 52 RTPrintf fmt; \ 53 cErrors++; \ 54 } \ 55 } while (0) 56 57 #define CHECK_pDef(paOpts, i) \ 58 CHECK2(Val.pDef == &(paOpts)[(i)], ("Got #%d (%p) expected #%d\n", (int)(Val.pDef - &(paOpts)[0]), Val.pDef, i)); 47 59 48 60 #define CHECK_GETOPT(expr, chRet, iInc) \ 49 61 do { \ 50 62 const int iPrev = GetState.iNext; \ 51 CHECK((expr) == (chRet)); \ 52 CHECK(GetState.iNext == (iInc) + iPrev); \ 63 const int rc = (expr); \ 64 CHECK2(rc == (chRet), ("got %d, expected %d\n", rc, (chRet))); \ 65 CHECK2(GetState.iNext == (iInc) + iPrev, ("iNext=%d expected %d\n", GetState.iNext, (iInc) + iPrev)); \ 53 66 GetState.iNext = (iInc) + iPrev; \ 54 67 } while (0) 55 68 69 70 56 71 /* 57 * Simple.72 * The basics. 58 73 */ 59 74 static const RTGETOPTDEF s_aOpts2[] = … … 64 79 { NULL, 'q', RTGETOPT_REQ_NOTHING }, 65 80 { "--quiet", 384, RTGETOPT_REQ_NOTHING }, 66 { "-startvm", 385, RTGETOPT_REQ_NOTHING }, 81 { "-novalue", 385, RTGETOPT_REQ_NOTHING }, 82 { "-startvm", 386, RTGETOPT_REQ_STRING }, 83 { "nodash", 387, RTGETOPT_REQ_NOTHING }, 84 { "nodashval", 388, RTGETOPT_REQ_STRING }, 67 85 }; 68 86 … … 71 89 "-s", "string1", 72 90 "--optwithstring", "string2", 91 73 92 "-i", "-42", 74 93 "-i:-42", … … 76 95 "-i:", "-42", 77 96 "-i=", "-42", 97 78 98 "--optwithint", "42", 79 99 "--optwithint:42", … … 81 101 "--optwithint:", "42", 82 102 "--optwithint=", "42", 103 83 104 "-v", 84 105 "--verbose", 85 106 "-q", 86 107 "--quiet", 87 "-startvm", 108 109 "-novalue", 110 "-startvm", "myvm", 111 112 "nodash", 113 "nodashval", "string3", 114 88 115 "filename1", 89 116 "-q", 90 117 "filename2", 118 119 "-vqi999", 91 120 NULL 92 121 }; … … 125 154 126 155 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'v', 1); 127 CHECK (Val.pDef == &s_aOpts2[2]);156 CHECK_pDef(s_aOpts2, 2); 128 157 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'v', 1); 129 CHECK(Val.pDef == &s_aOpts2[2]); 158 CHECK_pDef(s_aOpts2, 2); 159 130 160 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'q', 1); 131 CHECK (Val.pDef == &s_aOpts2[3]);161 CHECK_pDef(s_aOpts2, 3); 132 162 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 384, 1); 133 CHECK(Val.pDef == &s_aOpts2[4]); 163 CHECK_pDef(s_aOpts2, 4); 164 165 /* -novalue / -startvm (single dash long options) */ 134 166 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 385, 1); 135 CHECK(Val.pDef == &s_aOpts2[5]); 136 167 CHECK_pDef(s_aOpts2, 5); 168 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 386, 2); 169 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "myvm")); 170 171 /* no-dash options */ 172 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 387, 1); 173 CHECK_pDef(s_aOpts2, 7); 174 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 388, 2); 175 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string3")); 176 177 /* non-option, option, non-option */ 137 178 CHECK_GETOPT(RTGetOpt(&GetState, &Val), VINF_GETOPT_NOT_OPTION, 1); 138 179 CHECK(Val.psz && !strcmp(Val.psz, "filename1")); 139 180 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'q', 1); 140 CHECK (Val.pDef == &s_aOpts2[3]);181 CHECK_pDef(s_aOpts2, 3); 141 182 CHECK_GETOPT(RTGetOpt(&GetState, &Val), VINF_GETOPT_NOT_OPTION, 1); 142 183 CHECK(Val.psz && !strcmp(Val.psz, "filename2")); 143 184 185 /* compress short options */ 186 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'v', 0); 187 CHECK_pDef(s_aOpts2, 2); 188 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'q', 0); 189 CHECK_pDef(s_aOpts2, 3); 190 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 191 CHECK(Val.i32 == 999); 192 193 /* the end */ 144 194 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 0, 0); 145 195 CHECK(Val.pDef == NULL);
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器