MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / testToStringHelper

Function testToStringHelper

3rd/uriparser/test/test.cpp:1117–1162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1115
1116namespace {
1117 bool testToStringHelper(const wchar_t * text) {
1118 // Parse
1119 UriParserStateW state;
1120 UriUriW uri;
1121 state.uri = &uri;
1122 int res = uriParseUriW(&state, text);
1123 if (res != 0) {
1124 uriFreeUriMembersW(&uri);
1125 return false;
1126 }
1127
1128 // Back to string, _huge_ limit
1129 wchar_t shouldbeTheSame[1024 * 8];
1130 res = uriToStringW(shouldbeTheSame, &uri, 1024 * 8, NULL);
1131 if (res != 0) {
1132 uriFreeUriMembersW(&uri);
1133 return false;
1134 }
1135
1136 // Compare
1137 bool equals = (0 == wcscmp(shouldbeTheSame, text));
1138 if (!equals) {
1139#ifdef HAVE_WPRINTF
1140 wprintf(L"\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", text, shouldbeTheSame);
1141#endif
1142 }
1143
1144 // Back to string, _exact_ limit
1145 const int len = static_cast<int>(wcslen(text));
1146 int charsWritten;
1147 res = uriToStringW(shouldbeTheSame, &uri, len + 1, &charsWritten);
1148 if ((res != 0) || (charsWritten != len + 1)) {
1149 uriFreeUriMembersW(&uri);
1150 return false;
1151 }
1152
1153 // Back to string, _too small_ limit
1154 res = uriToStringW(shouldbeTheSame, &uri, len, &charsWritten);
1155 if ((res == 0) || (charsWritten >= len + 1)) {
1156 uriFreeUriMembersW(&uri);
1157 return false;
1158 }
1159
1160 uriFreeUriMembersW(&uri);
1161 return equals;
1162 }
1163} // namespace
1164
1165TEST(UriSuite, TestToString) {

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected