| 1115 | |
| 1116 | namespace { |
| 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 | |
| 1165 | TEST(UriSuite, TestToString) { |