| 1698 | |
| 1699 | namespace { |
| 1700 | void testQueryListHelper(const wchar_t * input, int expectedItemCount) { |
| 1701 | int res; |
| 1702 | |
| 1703 | UriBool spacePlusConversion = URI_TRUE; |
| 1704 | UriBool normalizeBreaks = URI_FALSE; |
| 1705 | UriBreakConversion breakConversion = URI_BR_DONT_TOUCH; |
| 1706 | |
| 1707 | int itemCount; |
| 1708 | UriQueryListW * queryList; |
| 1709 | res = uriDissectQueryMallocExW(&queryList, &itemCount, |
| 1710 | input, input + wcslen(input), spacePlusConversion, breakConversion); |
| 1711 | ASSERT_TRUE(res == URI_SUCCESS); |
| 1712 | ASSERT_TRUE(itemCount == expectedItemCount); |
| 1713 | ASSERT_TRUE((queryList == NULL) == (expectedItemCount == 0)); |
| 1714 | |
| 1715 | if (expectedItemCount != 0) { |
| 1716 | // First |
| 1717 | int charsRequired; |
| 1718 | res = uriComposeQueryCharsRequiredExW(queryList, &charsRequired, spacePlusConversion, |
| 1719 | normalizeBreaks); |
| 1720 | ASSERT_TRUE(res == URI_SUCCESS); |
| 1721 | ASSERT_TRUE(charsRequired >= (int)wcslen(input)); |
| 1722 | |
| 1723 | wchar_t * recomposed = new wchar_t[charsRequired + 1]; |
| 1724 | int charsWritten; |
| 1725 | res = uriComposeQueryExW(recomposed, queryList, charsRequired + 1, |
| 1726 | &charsWritten, spacePlusConversion, normalizeBreaks); |
| 1727 | ASSERT_TRUE(res == URI_SUCCESS); |
| 1728 | ASSERT_TRUE(charsWritten <= charsRequired); |
| 1729 | ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1); |
| 1730 | ASSERT_TRUE(!wcscmp(input, recomposed)); |
| 1731 | delete [] recomposed; |
| 1732 | |
| 1733 | recomposed = NULL; |
| 1734 | res = uriComposeQueryMallocW(&recomposed, queryList); |
| 1735 | ASSERT_TRUE(res == URI_SUCCESS); |
| 1736 | ASSERT_TRUE(recomposed != NULL); |
| 1737 | ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1); |
| 1738 | ASSERT_TRUE(!wcscmp(input, recomposed)); |
| 1739 | free(recomposed); |
| 1740 | } |
| 1741 | |
| 1742 | uriFreeQueryListW(queryList); |
| 1743 | } |
| 1744 | } // namespace |
| 1745 | |
| 1746 | TEST(UriSuite, QueryList) { |