|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
class EGCPoolTest : public :: testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
setlocale(LC_ALL, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
@ -22,10 +23,20 @@ TEST_F(EGCPoolTest, Initialized) {
|
|
|
|
|
EXPECT_EQ(0, pool_.poolused);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(EGCPoolTest, UTF8EGC) {
|
|
|
|
|
const char* wstr = "☢";
|
|
|
|
|
int c;
|
|
|
|
|
auto ulen = utf8_gce_len(wstr, &c);
|
|
|
|
|
ASSERT_LT(0, ulen);
|
|
|
|
|
EXPECT_LT(0, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(EGCPoolTest, AddAndRemove) {
|
|
|
|
|
const char* wstr = "﷽";
|
|
|
|
|
size_t ulen;
|
|
|
|
|
ASSERT_EQ(0, egcpool_stash(&pool_, wstr, &ulen));
|
|
|
|
|
int c; // column count
|
|
|
|
|
ASSERT_LE(0, egcpool_stash(&pool_, wstr, &ulen, &c));
|
|
|
|
|
ASSERT_LT(0, c);
|
|
|
|
|
EXPECT_NE(nullptr, pool_.pool);
|
|
|
|
|
EXPECT_STREQ(pool_.pool, wstr);
|
|
|
|
|
EXPECT_LT(0, pool_.poolsize);
|
|
|
|
@ -41,10 +52,14 @@ TEST_F(EGCPoolTest, AddAndRemove) {
|
|
|
|
|
|
|
|
|
|
TEST_F(EGCPoolTest, AddTwiceRemoveFirst) {
|
|
|
|
|
const char* wstr = "血";
|
|
|
|
|
size_t u1, u2;
|
|
|
|
|
int o1 = egcpool_stash(&pool_, wstr, &u1);
|
|
|
|
|
int o2 = egcpool_stash(&pool_, wstr, &u2);
|
|
|
|
|
size_t u1, u2; // bytes consumed
|
|
|
|
|
int c1, c2; // column counts
|
|
|
|
|
int o1 = egcpool_stash(&pool_, wstr, &u1, &c1);
|
|
|
|
|
int o2 = egcpool_stash(&pool_, wstr, &u2, &c2);
|
|
|
|
|
ASSERT_LE(0, o1);
|
|
|
|
|
ASSERT_LT(o1, o2);
|
|
|
|
|
ASSERT_LT(0, c1);
|
|
|
|
|
ASSERT_EQ(c1, c2);
|
|
|
|
|
EXPECT_NE(nullptr, pool_.pool);
|
|
|
|
|
EXPECT_STREQ(pool_.pool + o1, wstr);
|
|
|
|
|
EXPECT_STREQ(pool_.pool + o2, wstr);
|
|
|
|
@ -61,9 +76,12 @@ TEST_F(EGCPoolTest, AddTwiceRemoveFirst) {
|
|
|
|
|
TEST_F(EGCPoolTest, AddTwiceRemoveSecond) {
|
|
|
|
|
const char* wstr = "血";
|
|
|
|
|
size_t u1, u2;
|
|
|
|
|
int o1 = egcpool_stash(&pool_, wstr, &u1);
|
|
|
|
|
int o2 = egcpool_stash(&pool_, wstr, &u2);
|
|
|
|
|
int c1, c2; // column counts
|
|
|
|
|
int o1 = egcpool_stash(&pool_, wstr, &u1, &c1);
|
|
|
|
|
int o2 = egcpool_stash(&pool_, wstr, &u2, &c2);
|
|
|
|
|
ASSERT_LT(o1, o2);
|
|
|
|
|
ASSERT_LT(0, c1);
|
|
|
|
|
ASSERT_EQ(c1, c2);
|
|
|
|
|
EXPECT_NE(nullptr, pool_.pool);
|
|
|
|
|
EXPECT_STREQ(pool_.pool + o1, wstr);
|
|
|
|
|
EXPECT_STREQ(pool_.pool + o2, wstr);
|
|
|
|
|