2019-11-24 17:36:46 +00:00
|
|
|
#include <notcurses.h>
|
|
|
|
#include "egcpool.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
class EGCPoolTest : public :: testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
2019-11-25 18:36:16 +00:00
|
|
|
setlocale(LC_ALL, nullptr);
|
2019-11-24 17:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
egcpool_dump(&pool_);
|
|
|
|
}
|
|
|
|
|
|
|
|
egcpool pool_{};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(EGCPoolTest, Initialized) {
|
|
|
|
EXPECT_EQ(nullptr, pool_.pool);
|
|
|
|
EXPECT_EQ(0, pool_.poolsize);
|
|
|
|
EXPECT_EQ(0, pool_.poolwrite);
|
|
|
|
EXPECT_EQ(0, pool_.poolused);
|
|
|
|
}
|
|
|
|
|
2019-11-25 18:36:16 +00:00
|
|
|
TEST_F(EGCPoolTest, UTF8EGC) {
|
|
|
|
const char* wstr = "☢";
|
|
|
|
int c;
|
2019-11-26 02:11:27 +00:00
|
|
|
auto ulen = utf8_egc_len(wstr, &c);
|
2019-11-25 18:36:16 +00:00
|
|
|
ASSERT_LT(0, ulen);
|
|
|
|
EXPECT_LT(0, c);
|
|
|
|
}
|
|
|
|
|
2019-11-26 01:45:44 +00:00
|
|
|
// we're gonna run both a composed latin a with grave, and then a latin a with
|
|
|
|
// a combining nonspacing grave
|
|
|
|
TEST_F(EGCPoolTest, UTF8EGCCombining) {
|
|
|
|
const char* w1 = "à"; // U+00E0, U+0000 (c3 a0)
|
|
|
|
const char* w2 = "à"; // U+0061, U+0300, U+0000 (61 cc 80)
|
2019-11-26 02:11:27 +00:00
|
|
|
const char* w3 = "a"; // U+0061, U+0000 (61)
|
|
|
|
int c1, c2, c3;
|
|
|
|
auto u1 = utf8_egc_len(w1, &c1);
|
|
|
|
auto u2 = utf8_egc_len(w2, &c2);
|
|
|
|
auto u3 = utf8_egc_len(w3, &c3);
|
2019-11-26 01:45:44 +00:00
|
|
|
ASSERT_EQ(2, u1);
|
|
|
|
ASSERT_EQ(3, u2);
|
2019-11-26 02:11:27 +00:00
|
|
|
ASSERT_EQ(1, u3);
|
2019-11-26 01:45:44 +00:00
|
|
|
ASSERT_EQ(1, c1);
|
|
|
|
ASSERT_EQ(1, c2);
|
2019-11-26 02:11:27 +00:00
|
|
|
ASSERT_EQ(1, c3);
|
2019-11-26 01:45:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 17:36:46 +00:00
|
|
|
TEST_F(EGCPoolTest, AddAndRemove) {
|
|
|
|
const char* wstr = "﷽";
|
2019-11-24 19:00:48 +00:00
|
|
|
size_t ulen;
|
2019-11-25 18:36:16 +00:00
|
|
|
int c; // column count
|
|
|
|
ASSERT_LE(0, egcpool_stash(&pool_, wstr, &ulen, &c));
|
|
|
|
ASSERT_LT(0, c);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_NE(nullptr, pool_.pool);
|
|
|
|
EXPECT_STREQ(pool_.pool, wstr);
|
|
|
|
EXPECT_LT(0, pool_.poolsize);
|
2019-11-24 19:00:48 +00:00
|
|
|
EXPECT_EQ(ulen + 1, pool_.poolused);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_LT(0, pool_.poolwrite);
|
|
|
|
EXPECT_LE(pool_.poolused, pool_.poolsize);
|
|
|
|
egcpool_release(&pool_, 0);
|
|
|
|
EXPECT_EQ('\0', *pool_.pool);
|
|
|
|
EXPECT_LT(0, pool_.poolsize);
|
|
|
|
EXPECT_EQ(0, pool_.poolused);
|
|
|
|
EXPECT_LT(0, pool_.poolwrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(EGCPoolTest, AddTwiceRemoveFirst) {
|
2019-11-24 19:00:48 +00:00
|
|
|
const char* wstr = "血";
|
2019-11-25 18:36:16 +00:00
|
|
|
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);
|
2019-11-24 17:36:46 +00:00
|
|
|
ASSERT_LT(o1, o2);
|
2019-11-25 18:36:16 +00:00
|
|
|
ASSERT_LT(0, c1);
|
|
|
|
ASSERT_EQ(c1, c2);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_NE(nullptr, pool_.pool);
|
2019-11-24 19:00:48 +00:00
|
|
|
EXPECT_STREQ(pool_.pool + o1, wstr);
|
|
|
|
EXPECT_STREQ(pool_.pool + o2, wstr);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_LT(0, pool_.poolsize);
|
2019-11-24 19:00:48 +00:00
|
|
|
EXPECT_EQ(u1 + u2 + 2, pool_.poolused);
|
|
|
|
EXPECT_EQ(u1 + u2 + 2, pool_.poolwrite);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_LE(pool_.poolused, pool_.poolsize);
|
|
|
|
egcpool_release(&pool_, o1);
|
|
|
|
EXPECT_EQ('\0', pool_.pool[o1]);
|
2019-11-24 19:00:48 +00:00
|
|
|
EXPECT_EQ(u2 + 1, pool_.poolused);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_LT(0, pool_.poolwrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(EGCPoolTest, AddTwiceRemoveSecond) {
|
2019-11-24 19:00:48 +00:00
|
|
|
const char* wstr = "血";
|
|
|
|
size_t u1, u2;
|
2019-11-25 18:36:16 +00:00
|
|
|
int c1, c2; // column counts
|
|
|
|
int o1 = egcpool_stash(&pool_, wstr, &u1, &c1);
|
|
|
|
int o2 = egcpool_stash(&pool_, wstr, &u2, &c2);
|
2019-11-24 17:36:46 +00:00
|
|
|
ASSERT_LT(o1, o2);
|
2019-11-25 18:36:16 +00:00
|
|
|
ASSERT_LT(0, c1);
|
|
|
|
ASSERT_EQ(c1, c2);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_NE(nullptr, pool_.pool);
|
2019-11-24 19:00:48 +00:00
|
|
|
EXPECT_STREQ(pool_.pool + o1, wstr);
|
|
|
|
EXPECT_STREQ(pool_.pool + o2, wstr);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_LT(0, pool_.poolsize);
|
2019-11-24 19:00:48 +00:00
|
|
|
EXPECT_EQ(u1 + u2 + 2, pool_.poolused);
|
|
|
|
EXPECT_EQ(u1 + u2 + 2, pool_.poolwrite);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_LE(pool_.poolused, pool_.poolsize);
|
|
|
|
egcpool_release(&pool_, o2);
|
|
|
|
EXPECT_EQ('\0', pool_.pool[o2]);
|
2019-11-24 19:00:48 +00:00
|
|
|
EXPECT_EQ(u2 + 1, pool_.poolused);
|
2019-11-24 17:36:46 +00:00
|
|
|
EXPECT_LT(0, pool_.poolwrite);
|
|
|
|
}
|