static void TestPackedUInt(skiatest::Reporter* reporter) { // we know that packeduint tries to write 1, 2 or 4 bytes for the length, // so we test values around each of those transitions (and a few others) const size_t sizes[] = { 0, 1, 2, 0xFC, 0xFD, 0xFE, 0xFF, 0x100, 0x101, 32767, 32768, 32769, 0xFFFD, 0xFFFE, 0xFFFF, 0x10000, 0x10001, 0xFFFFFD, 0xFFFFFE, 0xFFFFFF, 0x1000000, 0x1000001, 0x7FFFFFFE, 0x7FFFFFFF, 0x80000000, 0x80000001, 0xFFFFFFFE, 0xFFFFFFFF }; size_t i; char buffer[sizeof(sizes) * 4]; SkMemoryWStream wstream(buffer, sizeof(buffer)); for (i = 0; i < SK_ARRAY_COUNT(sizes); ++i) { bool success = wstream.writePackedUInt(sizes[i]); REPORTER_ASSERT(reporter, success); } wstream.flush(); SkMemoryStream rstream(buffer, sizeof(buffer)); for (i = 0; i < SK_ARRAY_COUNT(sizes); ++i) { size_t n = rstream.readPackedUInt(); if (sizes[i] != n) { ERRORF(reporter, "sizes:%x != n:%x\n", i, sizes[i], n); } } }
/** * @function loadCorrespondences */ void Tensor3D::loadCorrespondences( char* _filenames ) { std::string fullPath( _filenames ); std::fstream wstream( fullPath.c_str(), std::ios::in ); std::string str; while( !wstream.eof() ) { std::string str; wstream >> str; printf("String read: %s \n", str.c_str() ); if( str == "PPP" ) { readAndStore_PPP( wstream ); } else if( str == "LLL" ) { readAndStore_LLL( wstream ); } else if( str == "PLP" ) { readAndStore_PLP( wstream ); } else if( str == "PLL" ) { readAndStore_PLL( wstream ); } else { printf("Unknown string - Skipping \n"); } } // end while printCorrespondences(); }
// ============================================================================ // CCwrtRegistryServerSession::OpGetWebAttributeL() // Returns the attribute value for the widget // // ============================================================================ // TInt CCwrtRegistryServerSession::OpGetWebAttributeL( const RMessage2& aMessage ) { TInt l = aMessage.GetDesMaxLength( 0 ); HBufC8* msgData = HBufC8::NewLC( l ); TPtr8 readPtr( msgData->Des() ); aMessage.ReadL( 0, readPtr ); RDesReadStream stream( *msgData ); CleanupClosePushL( stream ); QString appId = DeserializeStringL( stream ); QString attribute = DeserializeStringL( stream ); QString defaultValue = DeserializeStringL( stream ); CleanupStack::PopAndDestroy( 2 ); //stream, msgData, QVariant attrValue = WebAppRegistry::instance()->getAttribute( appId, attribute, QVariant( defaultValue ) ); TInt maxLength = aMessage.GetDesMaxLength( 1 ); CBufFlat* buf = CBufFlat::NewL( maxLength ); CleanupStack::PushL( buf ); RBufWriteStream wstream( *buf ); // stream over the buffer CleanupClosePushL( wstream ); SerializeStringL( wstream, attrValue.toString() ); CleanupStack::PopAndDestroy( &wstream ); aMessage.WriteL( 1, buf->Ptr(0) ); CleanupStack::PopAndDestroy( buf ); // buf return KErrNone; }
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) { typedef boost::dynamic_bitset<Block> bitset_type; typedef bitset_test<bitset_type> Tests; //===================================================================== // Test stream operator<< { // The test "variables" are: the stream type and its state, the // exception mask, the width, the fill char and the padding side (left/right) std::ios::iostate masks[] = { std::ios::goodbit, std::ios::eofbit, std::ios::failbit, std::ios::eofbit | std::ios::failbit }; static std::string strings[] = { std::string(""), std::string("0"), std::string("1"), std::string("11100"), get_long_string() }; char fill_chars[] = { '*', 'x', ' ' }; std::size_t num_masks = sizeof(masks) / sizeof(masks[0]); std::size_t num_strings = sizeof(strings) / sizeof(strings[0]); std::size_t num_chars = sizeof(fill_chars) / sizeof(fill_chars[0]); std::fstream not_good_stream("dynamic_bitset_tests - this file shouldn't exist", std::ios::in); for (std::size_t mi = 0; mi < num_masks; ++mi) { for (std::size_t si = 0; si < num_strings; ++si) { std::streamsize slen = (std::streamsize)(strings[si].length()); assert( (std::numeric_limits<std::streamsize>::max)() >=(std::streamsize)(1+slen*2) ); for (std::size_t ci = 0; ci < num_chars; ++ci) { // note how "negative widths" are tested too const std::streamsize widths[] = { -1 - slen/2, 0, slen/2, 1 + slen*2 }; std::size_t num_widths = sizeof(widths) / sizeof(widths[0]); for (std::size_t wi = 0; wi < num_widths; ++wi) { std::streamsize w = widths[wi]; { // test 0 - stream !good() if(not_good_stream.good()) throw std::logic_error("Error in operator << tests" " - please, double check"); bitset_type b(strings[si]); not_good_stream.width(w); not_good_stream.fill(fill_chars[ci]); try { not_good_stream.exceptions(masks[mi]); } catch(...) {} Tests::stream_inserter(b, not_good_stream, "<unused_string>"); } { // test 1a - file stream bitset_type b(strings[si]); std::ofstream file(test_file_name(), std::ios::trunc); file.width(w); file.fill(fill_chars[ci]); file.exceptions(masks[mi]); Tests::stream_inserter(b, file, test_file_name()); } { //NOTE: there are NO string stream tests - gps } #if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS) { // test 1b - wide file stream bitset_type b(strings[si]); std::wofstream file(test_file_name()); file.width(w); file.fill(fill_chars[ci]); file.exceptions(masks[mi]); Tests::stream_inserter(b, file, test_file_name()); } #endif } } } } // for (; mi..) } //===================================================================== // Test stream operator>> { // The test "variables" are: the stream type, the exception mask, // the actual contents (and/or state) of the stream, and width. // // With few exceptions, each test case consists of writing a different // assortment of digits and "whitespaces" to a text stream and then checking // that what was written gets read back unchanged. That's NOT guaranteed by // the standard, unless the assortment always ends with a '\n' and satisfies // other conditions (see C99, 7.19.2/2), however it works in practice and is // a good "real life" test. Some characters, such as '\v' and '\f', are not // used exactly because they are the ones which will most likely give problems // on some systems (for instance '\f' could actually be written as a sequence // of new-lines, and we could never be able to read it back) [gps] // // Note how the bitset object is not initially empty. That helps checking // that it isn't erroneously clear()ed by operator>>. std::ios::iostate masks[] = { std::ios::goodbit, std::ios::eofbit, std::ios::failbit, std::ios::eofbit | std::ios::failbit }; const std::string spaces = "\t\n "; //"\t\n\v\f "; const std::string long_string = get_long_string(); /*const*/ static std::string strings[] = { // NOTE: "const" gives the usual problems with Borland // (in Tests::stream_extractor instantiation) #if !(defined __BORLANDC__ \ && BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101))) // Borland 5.5.1 with RW library crashes // empty string std::string(""), // no bitset spaces, #endif // no bitset std::string("x"), std::string("\t xyz"), // bitset of size 1 std::string("0"), std::string("1"), std::string(" 0 "), std::string(" 1 "), spaces + "1", "1" + spaces, spaces + "1" + spaces, std::string(" x1x "), std::string(" 1x "), // long bitset long_string, " " + long_string + " xyz", spaces + long_string, spaces + long_string + spaces }; //----------------------------------------------------- std::stringstream not_good_stream; not_good_stream << "test"; std::string sink; not_good_stream >> sink; // now the stream should be in eof state const std::size_t num_masks = sizeof(masks) / sizeof(masks[0]); const std::size_t num_strings = sizeof(strings) / sizeof(strings[0]); for (std::size_t mi = 0; mi < num_masks; ++mi) { for (std::size_t si = 0; si < num_strings; ++si) { const std::streamsize slen = (std::streamsize)(strings[si].length()); assert((std::numeric_limits<std::streamsize>::max)() >= (std::streamsize)(1+slen*2)); std::streamsize widths[] = { -1, 0, slen/2, slen, 1 + slen*2 }; std::size_t num_widths = sizeof(widths) / sizeof(widths[0]); for(std::size_t wi = 0; wi < num_widths; ++wi) { const std::streamsize w = widths[wi]; // test 0 - !good() stream { if(not_good_stream.good()) throw std::logic_error("Error in operator >> tests" " - please, double check"); bitset_type b(1, 15ul); // note: b is not empty not_good_stream.width(w); try { not_good_stream.exceptions(masks[mi]); } catch(...) {} std::string irrelevant; Tests::stream_extractor(b, not_good_stream, irrelevant); } // test 1a - (narrow) file stream { bitset_type b(1, 255ul); { std::ofstream f(test_file_name()); f << strings[si]; } std::ifstream f(test_file_name()); f.width(w); f.exceptions(masks[mi]); Tests::stream_extractor(b, f, strings[si]); } #if !defined(BOOST_NO_STRINGSTREAM) // test 2a - stringstream { bitset_type b(1, 255ul); std::istringstream stream(strings[si]); stream.width(w); stream.exceptions(masks[mi]); Tests::stream_extractor(b, stream, strings[si]); } #endif #if !defined(BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS) // test 1b - wchar_t file stream { std::wstring wstr = widen_string(strings[si]); bitset_type b(1, 255ul); { std::basic_ofstream<wchar_t> of(test_file_name()); of << wstr; } std::basic_ifstream<wchar_t> f(test_file_name()); f.width(w); f.exceptions(masks[mi]); Tests::stream_extractor(b, f, wstr); } // test 2b - wstringstream { bitset_type b(1, 255ul); std::wstring wstr = widen_string(strings[si]); std::wistringstream wstream(wstr); wstream.width(w); wstream.exceptions(masks[mi]); Tests::stream_extractor(b, wstream, wstr); } #endif // BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS } } } // for ( mi = 0; ...) } //===================================================================== // << Any other tests go here >> // ..... }