void LibetonyekUtilsTest::testReadUVar() { CPPUNIT_ASSERT_EQUAL(0UL, readUVar(makeStream("\x0", 1))); CPPUNIT_ASSERT_EQUAL(1UL, readUVar(makeStream("\x1", 1))); CPPUNIT_ASSERT_EQUAL(0x7fUL, readUVar(makeStream("\x7f", 1))); CPPUNIT_ASSERT_EQUAL(0x80UL, readUVar(makeStream("\x80\x1", 2))); CPPUNIT_ASSERT_EQUAL(0x81UL, readUVar(makeStream("\x81\x1", 2))); CPPUNIT_ASSERT_EQUAL(0x12345678UL, readUVar(makeStream("\xf8\xac\xd1\x91\x01", 5))); CPPUNIT_ASSERT_EQUAL(numeric_limits<uint64_t>::max(), readUVar(makeStream("\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1", 10))); CPPUNIT_ASSERT_THROW(readUVar(makeStream("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x2", 10)), std::range_error); CPPUNIT_ASSERT_THROW(readUVar(makeEmptyStream()), EndOfStreamException); CPPUNIT_ASSERT_THROW(readUVar(makeStream("\x80", 1)), EndOfStreamException); CPPUNIT_ASSERT_THROW(readUVar(makeStream("\xff\xff", 2)), EndOfStreamException); }
std::auto_ptr<IOChannel> NetworkAdapter::makeStream(const std::string& url, const std::string& /*postdata*/, const std::string& cachefile) { return makeStream(url, cachefile); }
void IWAFieldTest::testRepeated() { IWAUInt64Field field; CPPUNIT_ASSERT_NO_THROW(field.parse(makeStream(BYTES("\x1\x4\x8")), 3)); const uint64_t expected[] = {1, 4, 8}; const std::deque<uint64_t> &values = field.repeated(); CPPUNIT_ASSERT_EQUAL(ETONYEK_NUM_ELEMENTS(expected), values.size()); CPPUNIT_ASSERT(std::equal(values.begin(), values.end(), expected)); CPPUNIT_ASSERT(std::equal(field.begin(), field.end(), expected)); }
Audio::AudioStream *Sci1SongIterator::getAudioStream() { Common::List<Sci1Sample>::iterator sample = _samples.begin(); if (sample != _samples.end() && sample->delta <= 0) { Audio::AudioStream *feed = makeStream(sample->_data, sample->size, sample->format); _samples.erase(sample); return feed; } else return NULL; }
Audio::AudioStream *Sci0SongIterator::getAudioStream() { sfx_pcm_config_t conf; int offset; uint size; if (_sci0_get_pcm_data(this, &conf, &offset, &size)) return NULL; _channel.state = SI_STATE_FINISHED; /* Don't play both PCM and music */ return makeStream(_data.begin() + offset + SCI0_PCM_DATA_OFFSET, size, conf); }
void IWAFieldTest::testOptional() { { IWAUInt64Field field; CPPUNIT_ASSERT_EQUAL(uint64_t(4), get_optional_value_or(field, 4)); CPPUNIT_ASSERT_NO_THROW(field.parse(makeStream(BYTES("\x1\x4")), 2)); const boost::optional<uint64_t> &value = field.optional(); CPPUNIT_ASSERT(value); CPPUNIT_ASSERT_EQUAL(uint64_t(1), get(value)); CPPUNIT_ASSERT_EQUAL(uint64_t(1), get(field)); CPPUNIT_ASSERT_EQUAL(uint64_t(1), get_optional_value_or(field, 4)); } { IWASInt32Field field; CPPUNIT_ASSERT_NO_THROW(field.parse(makeStream(BYTES("\x3")), 1)); CPPUNIT_ASSERT(field); CPPUNIT_ASSERT_EQUAL(int32_t(-2), field.get()); const boost::optional<int64_t> value(field.optional()); CPPUNIT_ASSERT(value); CPPUNIT_ASSERT_EQUAL(int64_t(-2), get(value)); } }
void IWAFieldTest::testParse() { IWAUInt64Field field; CPPUNIT_ASSERT_NO_THROW(field.parse(makeStream(BYTES("\x1")), 1)); // repeated CPPUNIT_ASSERT(!field.empty()); CPPUNIT_ASSERT_EQUAL(size_t(1), field.size()); CPPUNIT_ASSERT_EQUAL(uint64_t(1), field[0]); // optional CPPUNIT_ASSERT(field.is()); CPPUNIT_ASSERT(bool(field)); CPPUNIT_ASSERT_EQUAL(uint64_t(1), field.get()); // parse another value CPPUNIT_ASSERT_NO_THROW(field.parse(makeStream(BYTES("\xac\x2")), 1)); CPPUNIT_ASSERT_EQUAL(size_t(2), field.size()); CPPUNIT_ASSERT_EQUAL(uint64_t(1), field[0]); CPPUNIT_ASSERT_EQUAL(uint64_t(300), field[1]); CPPUNIT_ASSERT_EQUAL(uint64_t(1), field.get()); }
void IWAFieldTest::testParsePacked() { IWAUInt64Field field; CPPUNIT_ASSERT_NO_THROW(field.parse(makeStream(BYTES("\x1\x4\x8\x10")), 3)); // repeated CPPUNIT_ASSERT_EQUAL(size_t(3), field.size()); CPPUNIT_ASSERT_EQUAL(uint64_t(1), field[0]); CPPUNIT_ASSERT_EQUAL(uint64_t(4), field[1]); CPPUNIT_ASSERT_EQUAL(uint64_t(8), field[2]); // optional CPPUNIT_ASSERT(field.is()); CPPUNIT_ASSERT_EQUAL(uint64_t(1), field.get()); }
void LogstreamBuilder::operator<<(Tee* tee) { makeStream(); // Adding a Tee counts for purposes of deciding to make a log message. // TODO: dassert(!_tee); _tee = tee; }
void LibetonyekUtilsTest::testReadSVar() { CPPUNIT_ASSERT_EQUAL(0L, readSVar(makeStream("\x0", 1))); CPPUNIT_ASSERT_EQUAL(-1L, readSVar(makeStream("\x1", 1))); CPPUNIT_ASSERT_EQUAL(1L, readSVar(makeStream("\x2", 1))); CPPUNIT_ASSERT_EQUAL(-2L, readSVar(makeStream("\x3", 1))); CPPUNIT_ASSERT_EQUAL(0x7fffffffL, readSVar(makeStream("\xfe\xff\xff\xff\xf", 5))); CPPUNIT_ASSERT_EQUAL(-0x80000000L, readSVar(makeStream("\xff\xff\xff\xff\xf", 5))); CPPUNIT_ASSERT_EQUAL(numeric_limits<int64_t>::max(), readSVar(makeStream("\xfe\xff\xff\xff\xff\xff\xff\xff\xff\x1", 10))); CPPUNIT_ASSERT_EQUAL(numeric_limits<int64_t>::min(), readSVar(makeStream("\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1", 10))); CPPUNIT_ASSERT_THROW(readSVar(makeStream("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x2", 10)), std::range_error); CPPUNIT_ASSERT_THROW(readSVar(makeStream("\x81\x80\x80\x80\x80\x80\x80\x80\x80\x2", 10)), std::range_error); CPPUNIT_ASSERT_THROW(readSVar(makeEmptyStream()), EndOfStreamException); CPPUNIT_ASSERT_THROW(readSVar(makeStream("\x80", 1)), EndOfStreamException); CPPUNIT_ASSERT_THROW(readSVar(makeStream("\xff\xff", 2)), EndOfStreamException); }