egcpool: unit tests for utf8 conversion #20

This commit is contained in:
nick black 2019-11-25 13:36:16 -05:00 committed by Nick Black
parent a2f4fae96a
commit 6f92ae92ab
4 changed files with 29 additions and 7 deletions

View File

@ -4,6 +4,7 @@
class CellTest : public :: testing::Test {
protected:
void SetUp() override {
setlocale(LC_ALL, nullptr);
if(getenv("TERM") == nullptr){
GTEST_SKIP();
}

View File

@ -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);

View File

@ -4,6 +4,7 @@
class NcplaneTest : public :: testing::Test {
protected:
void SetUp() override {
setlocale(LC_ALL, nullptr);
if(getenv("TERM") == nullptr){
GTEST_SKIP();
}
@ -13,6 +14,7 @@ class NcplaneTest : public :: testing::Test {
ASSERT_NE(nullptr, nc_);
n_ = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n_);
ASSERT_EQ(0, ncplane_cursor_move_yx(n_, 0, 0));
}
void TearDown() override {
@ -104,7 +106,7 @@ TEST_F(NcplaneTest, RejectBadRGB) {
TEST_F(NcplaneTest, EmitWchar) {
const char cchar[] = "";
cell c{};
cell_load(n_, &c, cchar);
EXPECT_EQ(strlen(cchar), cell_load(n_, &c, cchar));
EXPECT_EQ(strlen(cchar), ncplane_putc(n_, &c));
int x, y;
ncplane_cursor_yx(n_, &y, &x);

View File

@ -6,6 +6,7 @@
class NotcursesTest : public :: testing::Test {
protected:
void SetUp() override {
setlocale(LC_ALL, nullptr);
if(getenv("TERM") == nullptr){
GTEST_SKIP();
}