static int test_kstr_comparation_2(struct ymd_mach *vm) { const struct kstr *kz = kstr_fetch(vm, "aaaaa", -1); const struct kstr *zz = kstr_fetch(vm, "aaaaaa", 6); ASSERT_EQ(int, kz->marked, vm->gc.white); ASSERT_EQ(int, zz->marked, vm->gc.white); ASSERT_TRUE(kstr_equals(kz, kz)); ASSERT_TRUE(kstr_equals(zz, zz)); ASSERT_EQ(int, kstr_compare(kz, kz), 0); ASSERT_EQ(int, kstr_compare(zz, zz), 0); ASSERT_FALSE(kz == zz); ASSERT_NE(ulong, kz->hash, zz->hash); ASSERT_LT(int, kz->len, zz->len); ASSERT_STRNE(kz->land, zz->land); ASSERT_FALSE(kstr_equals(kz, zz)); ASSERT_LT(int, kstr_compare(kz, zz), 0); kz = kstr_fetch(vm, "aaaaab", -1); zz = kstr_fetch(vm, "aaaaaa", -1); ASSERT_NE(ulong, kz->hash, zz->hash); ASSERT_EQ(int, kz->len, zz->len); ASSERT_STRNE(kz->land, zz->land); ASSERT_FALSE(kstr_equals(kz, zz)); ASSERT_GT(int, kstr_compare(kz, zz), 0); return 0; }
TEST(GitRevision, ExistsOrNull) { if(GIT_SHORTREV_HASH) { ASSERT_STRNE(GIT_SHORTREV_HASH, ""); } }
/// @test Test util field library - ib_field_create() ib_field_create() TEST_F(TestIBUtilField, test_field_create) { ib_field_t *f; ib_status_t rc; const char *nulstrval = "TestValue"; ib_num_t numval = 5; ib_bytestr_t *bytestrval; const char *nulout; const char *nulcopy; nulcopy = ib_mm_strdup(MM(), nulstrval); ASSERT_STRNE(NULL, nulcopy); rc = ib_field_create(&f, MM(), IB_S2SL("test_nulstr"), IB_FTYPE_NULSTR, ib_ftype_nulstr_in(nulcopy)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); ASSERT_EQ(11UL, f->nlen); ASSERT_EQ(0, memcmp("test_nulstr", f->name, 11)); rc = ib_field_value(f, ib_ftype_nulstr_out(&nulout)); ASSERT_EQ(IB_OK, rc); ASSERT_STREQ(nulstrval, nulout); rc = ib_field_create(&f, MM(), IB_S2SL("test_num"), IB_FTYPE_NUM, ib_ftype_num_in(&numval)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); ASSERT_EQ(8UL, f->nlen); ASSERT_EQ(0, memcmp("test_num", f->name, 8)); rc = ib_bytestr_dup_mem(&bytestrval, MM(), (uint8_t *)nulstrval, strlen(nulstrval)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); rc = ib_field_create(&f, MM(), IB_S2SL("test_bytestr"), IB_FTYPE_BYTESTR, ib_ftype_bytestr_in(bytestrval)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); ASSERT_EQ(12UL, f->nlen); ASSERT_EQ(0, memcmp("test_bytestr", f->name, 12)); rc = ib_field_create(&f, MM(), IB_S2SL("test_nulstr_ex"), IB_FTYPE_NULSTR, ib_ftype_nulstr_in(nulstrval)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); rc = ib_field_create(&f, MM(), IB_S2SL("test_num_ex"), IB_FTYPE_NUM, ib_ftype_num_in(&numval)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); rc = ib_field_create(&f, MM(), IB_S2SL("test_bytestr_ex"), IB_FTYPE_BYTESTR, ib_ftype_bytestr_in(bytestrval)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); }
TEST_F(LLApiTest, testPrefixIntersection) { // creating the index RSIndex* index = RediSearch_CreateIndex("index", GetValue, NULL); RediSearch_CreateTagField(index, TAG_FIELD_NAME1); RediSearch_CreateTagField(index, TAG_FIELD_NAME2); char buff[1024]; int NUM_OF_DOCS = 1000; for (int i = 0; i < NUM_OF_DOCS; ++i) { sprintf(buff, "doc%d", i); RSDoc* d = RediSearch_CreateDocument(buff, strlen(buff), 1.0, NULL); sprintf(buff, "tag1-%d", i); RediSearch_DocumentAddFieldCString(d, TAG_FIELD_NAME1, buff, RSFLDTYPE_DEFAULT); sprintf(buff, "tag2-%d", i); RediSearch_DocumentAddFieldCString(d, TAG_FIELD_NAME2, buff, RSFLDTYPE_DEFAULT); RediSearch_SpecAddDocument(index, d); } RSQNode* qn1 = RediSearch_CreateTagNode(index, TAG_FIELD_NAME1); RSQNode* pqn1 = RediSearch_CreatePrefixNode(index, NULL, "tag1-"); RediSearch_QueryNodeAddChild(qn1, pqn1); RSQNode* qn2 = RediSearch_CreateTagNode(index, TAG_FIELD_NAME2); RSQNode* pqn2 = RediSearch_CreatePrefixNode(index, NULL, "tag2-"); RediSearch_QueryNodeAddChild(qn2, pqn2); RSQNode* iqn = RediSearch_CreateIntersectNode(index, 0); RediSearch_QueryNodeAddChild(iqn, qn1); RediSearch_QueryNodeAddChild(iqn, qn2); RSResultsIterator* iter = RediSearch_GetResultsIterator(iqn, index); ASSERT_TRUE(iter); for (size_t i = 0; i < NUM_OF_DOCS; ++i) { size_t len; const char* id = (const char*)RediSearch_ResultsIteratorNext(iter, index, &len); ASSERT_STRNE(id, NULL); } RediSearch_ResultsIteratorFree(iter); RediSearch_DropIndex(index); }
TEST(SimpleTest, FirstTest) { // ASSERT_* can be replaced by EXPECT_*. // ASSERT_* yields fatal failure and EXPECT_* yields nonfatal failure. ASSERT_TRUE(true); ASSERT_FALSE(false); ASSERT_EQ(42, 42); ASSERT_NE(false, true); ASSERT_LT(1, 2); ASSERT_LE(1, 1); EXPECT_LE(1, 2); ASSERT_GT(1, 0); ASSERT_GE(1, 0); ASSERT_GE(0, 0); ASSERT_STREQ("foo", "foo"); ASSERT_STRNE("foo", "Foo"); ASSERT_STRCASEEQ("foo", "FOO"); ASSERT_STRCASENE("foo", "bar"); ASSERT_STRCASENE("", nullptr); }
/// @test Test util path functions - ib_util_mkpath() TEST_F(TestIBUtilMkPath, mkpath) { ib_status_t rc; char *tmp; char path[pathsize_full+1]; struct stat sbuf; strcpy(m_basedir, "/tmp/XXXXXX"); tmp = mkdtemp(m_basedir); ASSERT_STRNE(NULL, tmp) << "mkdtemp() returned " << strerror(errno) << std::endl; snprintf(path, pathsize_full, "%s/a", m_basedir); rc = ib_util_mkpath(path, 0700); ASSERT_EQ(IB_OK, rc); ASSERT_EQ(0, stat(path, &sbuf)); ASSERT_TRUE(S_ISDIR(sbuf.st_mode)); ASSERT_EQ((mode_t)0700, (sbuf.st_mode & 0777)); snprintf(path, pathsize_full, "%s/a/b", m_basedir); rc = ib_util_mkpath(path, 0750); ASSERT_EQ(IB_OK, rc); ASSERT_EQ(0, stat(path, &sbuf)); ASSERT_TRUE(S_ISDIR(sbuf.st_mode)); ASSERT_EQ((mode_t)0750, (sbuf.st_mode & 0777)); snprintf(path, pathsize_full, "%s/b/c/d/e", m_basedir); rc = ib_util_mkpath(path, 0755); ASSERT_EQ(IB_OK, rc); ASSERT_EQ(0, stat(path, &sbuf)); ASSERT_TRUE(S_ISDIR(sbuf.st_mode)); ASSERT_EQ((mode_t)0755, (sbuf.st_mode & 0777)); }
/// @test Test util field library - ib_field_format() with nulstr TEST_F(TestIBUtilField, test_field_format_nulstr) { ib_field_t *f; ib_status_t rc; char fmtbuf1[8]; char fmtbuf2[32]; const char *nul1 = "\"a\n\""; const char *nul2 = "\fabcdefghijk\t"; const char *tname; const char *buf; char *nulcopy; nulcopy = MemPoolStrDup(nul1); ASSERT_STRNE(NULL, nulcopy); rc = ib_field_create(&f, MemPool(), IB_FIELD_NAME("test_nulstr"), IB_FTYPE_NULSTR, ib_ftype_nulstr_in(nulcopy)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); buf = ib_field_format(f, false, false, &tname, fmtbuf1, sizeof(fmtbuf1)); ASSERT_STREQ(nul1, fmtbuf1); ASSERT_STREQ("NULSTR", tname); ASSERT_EQ(buf, fmtbuf1); buf = ib_field_format(f, true, false, &tname, fmtbuf1, sizeof(fmtbuf1)); ASSERT_STREQ("\"\"a\n\"\"", fmtbuf1); ASSERT_STREQ("NULSTR", tname); ASSERT_EQ(buf, fmtbuf1); buf = ib_field_format(f, true, true, &tname, fmtbuf1, sizeof(fmtbuf1)); ASSERT_STREQ("\"\\\"a\\n\"", fmtbuf1); ASSERT_STREQ("NULSTR", tname); ASSERT_EQ(buf, fmtbuf1); nulcopy = MemPoolStrDup(nul2); ASSERT_STRNE(NULL, nulcopy); rc = ib_field_create(&f, MemPool(), IB_FIELD_NAME("test_nulstr"), IB_FTYPE_NULSTR, ib_ftype_nulstr_in(nulcopy)); ASSERT_EQ(IB_OK, rc); ASSERT_TRUE(f); buf = ib_field_format(f, false, false, NULL, fmtbuf1, sizeof(fmtbuf1)); ASSERT_STREQ("\fabcdef", fmtbuf1); ASSERT_EQ(buf, fmtbuf1); buf = ib_field_format(f, false, false, NULL, fmtbuf2, sizeof(fmtbuf2)); ASSERT_STREQ(nul2, fmtbuf2); ASSERT_EQ(buf, fmtbuf2); buf = ib_field_format(f, true, false, NULL, fmtbuf2, sizeof(fmtbuf2)); ASSERT_STREQ("\"\fabcdefghijk\t\"", fmtbuf2); ASSERT_EQ(buf, fmtbuf2); buf = ib_field_format(f, false, true, NULL, fmtbuf2, sizeof(fmtbuf2)); ASSERT_STREQ("\\fabcdefghijk\\t", fmtbuf2); ASSERT_EQ(buf, fmtbuf2); buf = ib_field_format(f, true, true, NULL, fmtbuf2, sizeof(fmtbuf2)); ASSERT_STREQ("\"\\fabcdefghijk\\t\"", fmtbuf2); ASSERT_EQ(buf, fmtbuf2); }