46 lines
1005 B
C++
46 lines
1005 B
C++
|
//
|
||
|
// Created by dongwenzhe on 2023/3/21.
|
||
|
//
|
||
|
|
||
|
//#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||
|
#include "uthash/utstring.h"
|
||
|
#include "doctest.h"
|
||
|
|
||
|
TEST_SUITE("UTString") {
|
||
|
|
||
|
TEST_CASE("Append") {
|
||
|
UT_string *s;
|
||
|
UT_string *t;
|
||
|
|
||
|
utstring_new(s);
|
||
|
utstring_new(t);
|
||
|
utstring_printf(s, "hello ");
|
||
|
utstring_printf(t, "world");
|
||
|
|
||
|
utstring_concat(s, t);
|
||
|
char *body = utstring_body(s);
|
||
|
|
||
|
MESSAGE(doctest::String(body));
|
||
|
CHECK(doctest::String(body) == "hello world");
|
||
|
|
||
|
utstring_free(s);
|
||
|
utstring_free(t);
|
||
|
}
|
||
|
|
||
|
TEST_CASE("Binary") {
|
||
|
UT_string *s;
|
||
|
utstring_new(s);
|
||
|
utstring_printf(s, "hello world");
|
||
|
MESSAGE(utstring_len(s));
|
||
|
|
||
|
char binary[] = "\xff\xff";
|
||
|
utstring_bincpy(s, binary, sizeof(binary));
|
||
|
MESSAGE(utstring_len(s));
|
||
|
char *body = utstring_body(s);
|
||
|
MESSAGE(doctest::String(body));
|
||
|
|
||
|
utstring_clear(s);
|
||
|
|
||
|
utstring_free(s);
|
||
|
}
|
||
|
}
|