void testCopyConstructor1() { Sn stdfStr("ABC"); TS_ASSERT_SAME_DATA(stdfStr.mData+2, "ABC", 3); TS_ASSERT_EQUALS(stdfStr.storage(), 5u); TS_ASSERT_EQUALS(stdfStr.max_size(), 65535u); Sn stdfStrC (stdfStr); TS_ASSERT_SAME_DATA(stdfStrC.mData+2, "ABC", 3); TS_ASSERT_EQUALS(stdfStrC.storage(), 5u); TS_ASSERT_EQUALS(stdfStrC.max_size(), 65535u); }
void testConstructor2() { Sn stdfStr; TS_ASSERT_SAME_DATA(stdfStr.mData, "", 1); TS_ASSERT_EQUALS(stdfStr.storage(), 2u); TS_ASSERT_EQUALS(stdfStr.max_size(), 65535u); stdfStr += ""; TS_ASSERT_SAME_DATA(stdfStr.mData, "", 1); TS_ASSERT_EQUALS(stdfStr.storage(), 2u); TS_ASSERT_EQUALS(stdfStr.max_size(), 65535u); }
void testAssigner1() { Sn stdfStr("ABC"); TS_ASSERT_SAME_DATA(stdfStr.mData+2, "ABC", 3); TS_ASSERT_EQUALS(stdfStr.storage(), 5u); TS_ASSERT_EQUALS(stdfStr.max_size(), 65535u); Sn stdfStrC; stdfStrC = stdfStr; TS_ASSERT_SAME_DATA(stdfStrC.mData+2, "ABC", 3); TS_ASSERT_EQUALS(stdfStrC.storage(), 5u); TS_ASSERT_EQUALS(stdfStrC.max_size(), 65535u); }
void testCopyConstructor1() { B6 source("00000001"); B6 stdfStr(source); unsigned char ch = 1; TS_ASSERT_SAME_DATA(stdfStr.mData, &ch, 1); TS_ASSERT_EQUALS(stdfStr[0], 1); TS_ASSERT_EQUALS(stdfStr.to_string(), std::basic_string<char>("000000000000000000000000000000000000000000000001")); stdfStr = "10000000"; ch = 128; TS_ASSERT_SAME_DATA(stdfStr.mData, &ch, 1); TS_ASSERT_EQUALS(stdfStr.to_string(), std::basic_string<char>("000000000000000000000000000000000000000010000000")); TS_ASSERT_EQUALS(stdfStr[7], 1); TS_ASSERT_EQUALS(source.to_string(), std::basic_string<char>("000000000000000000000000000000000000000000000001")); }
void test_to_chars() { String* s = String::create(state, "xy"); ByteArray* b = s->data(); char* chars = b->to_chars(state); TS_ASSERT_SAME_DATA("xy", chars, 2); }
void test_to_chars() { String* s = String::create(state, "xy"); CharArray* c = s->data(); char* chars = c->to_chars(state, Fixnum::from(2)); TS_ASSERT_SAME_DATA("xy", chars, 2); }
void testWriteRead3() { const char *filename = "TestB6.testWriteRead3.txt"; B6 stdfStrIn; stdfStrIn[0] = 1; stdfStrIn[6] = 1; stdfStrIn[26] = 1; std::ofstream outfile(filename, std::ofstream::binary); stdfStrIn.write(outfile); outfile.close(); B6 stdfStrOut; std::ifstream infile(filename, std::ifstream::binary); stdfStrOut.read(infile); outfile.close(); TS_ASSERT_SAME_DATA(stdfStrIn.mData, stdfStrOut.mData, SIZE); TS_ASSERT_EQUALS(stdfStrIn.to_string(), "000000000000000000000100000000000000000001000001"); TS_ASSERT_EQUALS(stdfStrOut.to_string(), "000000000000000000000100000000000000000001000001"); TS_ASSERT_EQUALS(stdfStrIn[0], 1); TS_ASSERT_EQUALS(stdfStrOut[0], 1); TS_ASSERT_EQUALS(stdfStrIn[6], 1); TS_ASSERT_EQUALS(stdfStrOut[6], 1); TS_ASSERT_EQUALS(stdfStrIn[26], 1); TS_ASSERT_EQUALS(stdfStrOut[26], 1); TS_ASSERT_EQUALS(stdfStrIn.storage(), SIZE); TS_ASSERT_EQUALS(stdfStrOut.storage(), SIZE); }
void testConstructor2() { B6 stdfStr = ""; unsigned char ch[SIZE] = {0}; TS_ASSERT_SAME_DATA(stdfStr.mData, ch, SIZE); TS_ASSERT_EQUALS(stdfStr.to_string(), "000000000000000000000000000000000000000000000000"); TS_ASSERT_EQUALS(stdfStr.storage(), SIZE); }
void testConstructor3() { B6 stdfStr("0100000100100000001"); unsigned char ch[SIZE] = {0}; ch[0] = 1; ch[1] = 9; ch[2] = 2; TS_ASSERT_SAME_DATA(stdfStr.mData, ch, SIZE); TS_ASSERT_EQUALS(stdfStr.to_string(), std::basic_string<char>("000000000000000000000000000000100000100100000001")); stdfStr = "1000000000000001"; memset(ch, 0, SIZE); ch[0] = 1; ch[1] = 128; TS_ASSERT_SAME_DATA(stdfStr.mData, ch, SIZE); TS_ASSERT_EQUALS(stdfStr.to_string(), std::basic_string<char>("000000000000000000000000000000001000000000000001")); stdfStr.reset(1); TS_ASSERT_EQUALS(stdfStr.to_string(), "111111111111111111111111111111111111111111111111"); stdfStr.reset(0); TS_ASSERT_EQUALS(stdfStr.to_string(), "000000000000000000000000000000000000000000000000"); stdfStr[0] = 1; TS_ASSERT_EQUALS(stdfStr.to_string(), "000000000000000000000000000000000000000000000001"); TS_ASSERT_EQUALS(stdfStr[0], 1); TS_ASSERT_EQUALS(stdfStr[1], 0); TS_ASSERT_EQUALS(stdfStr[2], 0); TS_ASSERT_EQUALS(stdfStr[3], 0); TS_ASSERT_EQUALS(stdfStr[4], 0); TS_ASSERT_EQUALS(stdfStr[5], 0); TS_ASSERT_EQUALS(stdfStr[6], 0); TS_ASSERT_EQUALS(stdfStr[7], 0); TS_ASSERT_EQUALS(stdfStr[47], 0); stdfStr.reset(0); TS_ASSERT_EQUALS(stdfStr.to_string(), "000000000000000000000000000000000000000000000000"); stdfStr[47] = 1; TS_ASSERT_EQUALS(stdfStr.to_string(), "100000000000000000000000000000000000000000000000"); TS_ASSERT_EQUALS(stdfStr[0], 0); TS_ASSERT_EQUALS(stdfStr[1], 0); TS_ASSERT_EQUALS(stdfStr[2], 0); TS_ASSERT_EQUALS(stdfStr[3], 0); TS_ASSERT_EQUALS(stdfStr[4], 0); TS_ASSERT_EQUALS(stdfStr[5], 0); TS_ASSERT_EQUALS(stdfStr[6], 0); TS_ASSERT_EQUALS(stdfStr[7], 0); TS_ASSERT_EQUALS(stdfStr[47], 1); }
void test_method_to_s_singleton() { Symbol* meth = state->symbol("meth"); Symbol* klass = state->symbol("Object"); profiler::Method method(0U, meth, klass, profiler::kSingleton); String* name = method.to_s(state); TS_ASSERT_SAME_DATA("Object.meth", name->byte_address(), 11); }
void test_write() { char buf[4]; String* s = String::create(state, "abdc"); io->write(state, s); lseek(fd, 0, SEEK_SET); TS_ASSERT_EQUALS(::read(fd, buf, 4U), 4); TS_ASSERT_SAME_DATA(buf, "abdc", 4); }
void testMerge() { Sn stdfStr; std::basic_string<char> str; str = ""; stdfStr.clear(); stdfStr += str; TS_ASSERT(stdfStr.to_string() == str); TS_ASSERT_SAME_DATA(stdfStr.mData, "", 1); str.clear(); str.assign(stdfStr.max_size()+1, 'A'); stdfStr.clear(); stdfStr += str; str[0] = 0xFF; str[1] = 0xFF; TS_ASSERT_SAME_DATA(stdfStr.mData, str.data(), stdfStr.max_size()+1); str = "123456789"; stdfStr.clear(); stdfStr += str; TS_ASSERT(stdfStr.to_string() == str); str.insert(0, 2, 0x0); str[0] = 0x09; str[1] = 0x00; TS_ASSERT_SAME_DATA(stdfStr.mData, str.data(), str.size()+1); str.clear(); str.assign(stdfStr.max_size()-5, 'A'); stdfStr.clear(); stdfStr += str; TS_ASSERT(stdfStr.to_string() == str); str.insert(0, 2, 0x0); str[0] = 0xFF-5; str[1] = 0xFF; TS_ASSERT_SAME_DATA(stdfStr.mData, str.data(), stdfStr.max_size()-4); std::basic_string<char> str1 = "123456789"; stdfStr += str1; str[0] = 0xFF; str += str1; TS_ASSERT_SAME_DATA(stdfStr.mData, str.data(), stdfStr.max_size()+1); }
void testClone1() { Sn stdfStr("ABC"); TS_ASSERT_SAME_DATA(stdfStr.mData+2, "ABC", 3); TS_ASSERT_EQUALS(stdfStr.storage(), 5u); TS_ASSERT_EQUALS(stdfStr.max_size(), 65535u); DataType::DataTypeSharedPtr stdfStrP = stdfStr.clone(); TS_ASSERT(stdfStrP->to_string() == "ABC"); TS_ASSERT_EQUALS(stdfStrP->storage(), 5u); TS_ASSERT_DIFFERS(stdfStrP.get(), &stdfStr); }
void test_control_seeks_to_a_known_position() { char *dir = make_directory(); String* path = String::create(state, dir); d->open(state, path); d->read(state); Fixnum* pos = (Fixnum*)d->control(state, Fixnum::from(2), Fixnum::from(0)); String* first = as<String>(d->read(state)); d->control(state, Fixnum::from(0), pos); String* second = as<String>(d->read(state)); TS_ASSERT_EQUALS(first->size(), second->size()); TS_ASSERT_SAME_DATA(first, second, first->size()); remove_directory(dir); }
void testWriteRead2() { const char *filename = "TestB6.testWriteRead2.txt"; B6 stdfStrIn("11111111000000011111111"); std::ofstream outfile(filename, std::ofstream::binary); stdfStrIn.write(outfile); outfile.close(); B6 stdfStrOut; std::ifstream infile(filename, std::ifstream::binary); stdfStrOut.read(infile); outfile.close(); TS_ASSERT_SAME_DATA(stdfStrIn.mData, stdfStrOut.mData, SIZE); TS_ASSERT_EQUALS(stdfStrIn.to_string(), "000000000000000000000000011111111000000011111111"); TS_ASSERT_EQUALS(stdfStrOut.to_string(), "000000000000000000000000011111111000000011111111"); }
void test_move_bytes() { String* s = String::create(state, "xyzzy"); CharArray* c = s->data(); c->move_bytes(state, Fixnum::from(0), Fixnum::from(2), Fixnum::from(3)); TS_ASSERT_SAME_DATA(c->raw_bytes(), "xyzxy", 5); }
void test_fetch_bytes() { String* s = String::create(state, "xyzzy"); CharArray* c = s->data(); CharArray* ca = c->fetch_bytes(state, Fixnum::from(1), Fixnum::from(3)); TS_ASSERT_SAME_DATA(ca->raw_bytes(), "yzz", 3); }
void test_move_bytes() { ByteArray* b = new_bytearray("xyzzy"); b->move_bytes(state, Fixnum::from(0), Fixnum::from(2), Fixnum::from(3)); TS_ASSERT_SAME_DATA(b->raw_bytes(), "xyzxy", 5); }
void test_fetch_bytes() { String* s = String::create(state, "xyzzy"); ByteArray* b = s->data(); ByteArray* ba = b->fetch_bytes(state, Fixnum::from(1), Fixnum::from(3)); TS_ASSERT_SAME_DATA(ba->bytes, "yzz", 3); }
void test_move_bytes() { String* s = String::create(state, "xyzzy"); ByteArray* b = s->data(); b->move_bytes(state, Fixnum::from(0), Fixnum::from(2), Fixnum::from(3)); TS_ASSERT_SAME_DATA(b->bytes, "xyzxy", 5); }
void test_fetch_bytes() { ByteArray* b = new_bytearray("xyzzy"); ByteArray* ba = b->fetch_bytes(state, Fixnum::from(1), Fixnum::from(3)); TS_ASSERT_SAME_DATA(ba->raw_bytes(), "yzz", 3); }