diff options
author | Max Kellermann <max@musicpd.org> | 2019-08-09 16:27:42 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-08-09 20:39:34 +0200 |
commit | 7654038d65641cbce39119389c8fcf530c6638ba (patch) | |
tree | 21c7ddecfcaab892c3fcdefbb66fb214006e65ce /test/TestUriQueryParser.cxx | |
parent | e4612ecb66e78f147396c251ee47bbb940a2fc51 (diff) |
util/UriQueryParser: new library
Diffstat (limited to 'test/TestUriQueryParser.cxx')
-rw-r--r-- | test/TestUriQueryParser.cxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/TestUriQueryParser.cxx b/test/TestUriQueryParser.cxx new file mode 100644 index 000000000..9455f0664 --- /dev/null +++ b/test/TestUriQueryParser.cxx @@ -0,0 +1,34 @@ +/* + * Unit tests for src/util/ + */ + +#include "util/UriQueryParser.hxx" +#include "util/StringView.hxx" + +#include <gtest/gtest.h> + +static bool +operator==(StringView a, StringView b) +{ + if (a.IsNull() || b.IsNull()) + return a.IsNull() == b.IsNull(); + + return a.Equals(b); +} + +TEST(UriQueryParser, UriFindRawQueryParameter) +{ + const char *q = "foo=1&bar=2"ed=%20%00+%%&empty1&empty2="; + EXPECT_EQ(UriFindRawQueryParameter(q, "doesntexist"), + (const char *)nullptr); + EXPECT_EQ(UriFindRawQueryParameter(q, "foo"), + "1"); + EXPECT_EQ(UriFindRawQueryParameter(q, "bar"), + "2"); + EXPECT_EQ(UriFindRawQueryParameter(q, "quoted"), + "%20%00+%%"); + EXPECT_EQ(UriFindRawQueryParameter(q, "empty1"), + ""); + EXPECT_EQ(UriFindRawQueryParameter(q, "empty2"), + ""); +} |