nghttp2/src/util_test.cc

97 lines
3.1 KiB
C++
Raw Normal View History

2013-08-27 17:09:46 +02:00
/*
2014-03-30 12:09:21 +02:00
* nghttp2 - HTTP/2 C Library
2013-08-27 17:09:46 +02:00
*
* Copyright (c) 2013 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "util_test.h"
#include <iostream>
#include <CUnit/CUnit.h>
#include "util.h"
using namespace nghttp2;
namespace shrpx {
void test_util_streq(void)
{
CU_ASSERT(util::streq("alpha", (const uint8_t*)"alpha", 5));
CU_ASSERT(util::streq("alpha", (const uint8_t*)"alphabravo", 5));
CU_ASSERT(!util::streq("alpha", (const uint8_t*)"alphabravo", 6));
CU_ASSERT(!util::streq("alphabravo", (const uint8_t*)"alpha", 5));
CU_ASSERT(!util::streq("alpha", (const uint8_t*)"alphA", 5));
CU_ASSERT(!util::streq("", (const uint8_t*)"a", 1));
CU_ASSERT(util::streq("", (const uint8_t*)"", 0));
CU_ASSERT(!util::streq("alpha", (const uint8_t*)"", 0));
CU_ASSERT(util::streq((const uint8_t*)"alpha", 5,
(const uint8_t*)"alpha", 5));
CU_ASSERT(!util::streq((const uint8_t*)"alpha", 4,
(const uint8_t*)"alpha", 5));
CU_ASSERT(!util::streq((const uint8_t*)"alpha", 5,
(const uint8_t*)"alpha", 4));
CU_ASSERT(!util::streq((const uint8_t*)"alpha", 5,
(const uint8_t*)"alphA", 5));
char *a = nullptr;
char *b = nullptr;
CU_ASSERT(util::streq(a, 0, b, 0));
2013-08-27 17:09:46 +02:00
}
void test_util_strieq(void)
{
CU_ASSERT(util::strieq(std::string("alpha"), std::string("alpha")));
CU_ASSERT(util::strieq(std::string("alpha"), std::string("AlPhA")));
CU_ASSERT(util::strieq(std::string(), std::string()));
CU_ASSERT(!util::strieq(std::string("alpha"), std::string("AlPhA ")));
CU_ASSERT(!util::strieq(std::string(), std::string("AlPhA ")));
}
2013-08-27 17:09:46 +02:00
void test_util_inp_strlower(void)
{
std::string a("alPha");
util::inp_strlower(a);
CU_ASSERT("alpha" == a);
a = "ALPHA123BRAVO";
util::inp_strlower(a);
CU_ASSERT("alpha123bravo" == a);
a = "";
util::inp_strlower(a);
CU_ASSERT("" == a);
}
2013-11-09 08:18:01 +01:00
void test_util_to_base64(void)
{
std::string x = "AAA--B_";
util::to_base64(x);
CU_ASSERT("AAA++B/=" == x);
x = "AAA--B_B";
util::to_base64(x);
CU_ASSERT("AAA++B/B" == x);
}
2013-08-27 17:09:46 +02:00
} // namespace shrpx