void RunTestExToNulBuf(const TextBuf &input, const TextBuf &expected, size_t bufsize, ib_status_t expected_rc) { char buf[bufsize]; size_t len; ib_status_t rc; ib_flags_t result; rc = ExecExToNulBuf(input.GetUBuf(), input.GetLen(), buf, bufsize, len, result); if (rc == IB_ENOTIMPL) { return; } const char *name = TestName(IB_STROP_BUF, TYPE_EX_TO_STR); ASSERT_EQ(expected_rc, rc) << name; TextBuf output(buf); CheckResult(name, input, expected, IB_STRFLAG_NONE, IB_STRFLAG_MODIFIED, rc, result, output); }
size_t Set(const TextBuf &other) { if (other.IsByteStr() ) { return SetText(other.GetText(), other.GetLen()); } else { return SetStr(other.GetStr()); } }
void CheckResult(const char *name, const TextBuf &input, const TextBuf &expected, ib_flags_t expected_unmodified_result, ib_flags_t expected_modified_result, ib_status_t rc, ib_flags_t result, const TextBuf &output) { const char *modstr; ib_flags_t eresult; if ( (rc == IB_ETRUNC) || (input != expected) ) { eresult = expected_modified_result; modstr = "should be modified"; } else { eresult = expected_unmodified_result; modstr = "should not be modified"; } ASSERT_EQ(eresult, result) << name << " " << modstr << " " << std::endl << " Expected: " << " [" << expected.GetLen() << "]" << " \"" << expected.GetFmt() << "\"" << std::endl << " Actual: " << " [" << output.GetLen() << "]" << " \"" << output.GetFmt() << "\""; if (rc != IB_ETRUNC) { ASSERT_TRUE(expected == output) << name << std::endl << " Expected: " << " [" << expected.GetLen() << "]" << " \"" << expected.GetFmt() << "\"" << std::endl << " Actual: " << " [" << output.GetLen() << "]" << " \"" << output.GetFmt() << "\""; } }
bool operator == (const TextBuf &other) const { if (IsNull() || other.IsNull() ) { return false; } if (IsByteStr() || other.IsByteStr()) { if (GetLen() != other.GetLen()) { return false; } else if (GetLen() == 0) { return true; } else { return (memcmp(GetBuf(), other.GetBuf(), GetLen()) == 0); } } else { return (strcmp(GetBuf(), other.GetBuf()) == 0); } };
void RunTestCopyExToNul(const TextBuf &input, const TextBuf &expected) { ib_status_t rc; size_t len = input.GetLen(); char *out; ib_flags_t result; rc = ExecCopyExToNul(input.GetUBuf(), len, &out, result); if (rc == IB_ENOTIMPL) { return; } const char *name = TestName(IB_STROP_COPY, TYPE_NUL); ASSERT_EQ(IB_OK, rc) << name; TextBuf output(out); CheckResult(name, input, expected, IB_STRFLAG_NEWBUF, (IB_STRFLAG_NEWBUF | IB_STRFLAG_MODIFIED), rc, result, output); }
void RunTestCowEx(const TextBuf &input, const TextBuf &expected) { size_t len = input.GetLen(); uint8_t *out; ib_status_t rc; size_t outlen; ib_flags_t result; rc = ExecCowEx(input.GetUBuf(), len, &out, outlen, result); if (rc == IB_ENOTIMPL) { return; } const char *name = TestName(IB_STROP_COW, TYPE_EX); ASSERT_EQ(IB_OK, rc) << name; TextBuf output(out, outlen); CheckResult(name, input, expected, IB_STRFLAG_ALIAS, (IB_STRFLAG_NEWBUF | IB_STRFLAG_MODIFIED), rc, result, output); }
void RunTestInplaceNul(const TextBuf &input, const TextBuf &expected) { size_t len = input.GetLen(); char buf[len]; ib_status_t rc; ib_flags_t result; strcpy(buf, input.GetStr()); rc = ExecInplaceNul(buf, result); if (rc == IB_ENOTIMPL) { return; } const char *name = TestName(IB_STROP_INPLACE, TYPE_NUL); ASSERT_EQ(IB_OK, rc) << name; TextBuf output(buf); CheckResult(name, input, expected, IB_STRFLAG_ALIAS, (IB_STRFLAG_ALIAS | IB_STRFLAG_MODIFIED), rc, result, output); }
void RunTestInplaceEx(const TextBuf &input, const TextBuf &expected) { size_t len = input.GetLen(); uint8_t buf[len]; ib_status_t rc; size_t outlen; ib_flags_t result; memcpy(buf, input.GetBuf(), len); rc = ExecInplaceEx(buf, len, outlen, result); if (rc == IB_ENOTIMPL) { return; } const char *name = TestName(IB_STROP_INPLACE, TYPE_EX); ASSERT_EQ(IB_OK, rc) << name; TextBuf output(buf, outlen); CheckResult(name, input, expected, IB_STRFLAG_ALIAS, (IB_STRFLAG_ALIAS | IB_STRFLAG_MODIFIED), rc, result, output); }