void AssemFlowGraph::checkTempsUsedUndefined(const asm_function & func, const LiveMap<asm_statement *> & lm) const { CHECK_THROW( (getListOfNodes().begin() != getListOfNodes().end()), WrongArgumentException("Not possible to check for temporaries used, while" " undefined, because an empty function was passed.") ); const NodeType * const node = &*(this->getListOfNodes().begin()); const LiveMap<asm_statement*>::um_c_iterator liveIns = lm.liveIn.find(node); CHECK_THROW( liveIns != lm.liveIn.end(), WrongArgumentException("Live map doesn't correspond to the function") ); const LiveMap<asm_statement *>::UIDSetType & usedUndef = liveIns->second; /// The unwanted std::vector<uint32_t> uninit; VerifyUninitialized verifier(uninit); for_each(usedUndef.begin(), usedUndef.end(), verifier ); if (!uninit.empty()) { std::stringstream stream; ReportUninitialized reporter(stream, tempsMap, *this); stream << "Found temporaries used without being initialized, in " << "function: " << func.name << std::endl; for_each(uninit.begin(), uninit.end(), reporter); throw WrongArgumentException(stream.str()); } }
TEST_FIXTURE(page_blob_test_base, existing_page_blob_write_stream) { CHECK_THROW(m_blob.open_write(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); azure::storage::blob_request_options options; options.set_store_blob_content_md5(true); std::vector<uint8_t> buffer; buffer.resize(16 * 1024); fill_buffer_and_get_md5(buffer); m_blob.upload_from_stream(concurrency::streams::bytestream::open_istream(buffer), 0, azure::storage::access_condition(), options, m_context); CHECK_THROW(m_blob.open_write(azure::storage::access_condition(), options, m_context), std::logic_error); options.set_store_blob_content_md5(false); auto stream = m_blob.open_write(azure::storage::access_condition(), options, m_context); stream.seek(512); stream.streambuf().putn_nocopy(buffer.data(), 512).wait(); stream.close().wait(); concurrency::streams::container_buffer<std::vector<uint8_t>> downloaded_blob; CHECK_THROW(m_blob.download_to_stream(downloaded_blob.create_ostream(), azure::storage::access_condition(), options, m_context), azure::storage::storage_exception); downloaded_blob.seekpos(0, std::ios_base::out); options.set_disable_content_md5_validation(true); m_blob.download_to_stream(downloaded_blob.create_ostream(), azure::storage::access_condition(), options, m_context); CHECK_ARRAY_EQUAL(buffer.data(), downloaded_blob.collection().data(), 512); CHECK_ARRAY_EQUAL(buffer.data(), downloaded_blob.collection().data() + 512, 512); CHECK_ARRAY_EQUAL(buffer.data() + 1024, downloaded_blob.collection().data() + 1024, (int)(buffer.size()) - 1024); }
TEST_FIXTURE(page_blob_test_base, page_blob_sequence_number) { m_blob.properties().set_content_language(U("tr,en")); m_blob.create(512, 0, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_EQUAL(512, m_blob.properties().size()); CHECK_EQUAL(0, m_blob.properties().page_blob_sequence_number()); m_blob.properties().set_content_language(U("en")); m_blob.set_sequence_number(azure::storage::sequence_number::update(5), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_EQUAL(5, m_blob.properties().page_blob_sequence_number()); m_blob.set_sequence_number(azure::storage::sequence_number::maximum(7), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_EQUAL(7, m_blob.properties().page_blob_sequence_number()); m_blob.set_sequence_number(azure::storage::sequence_number::maximum(3), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_EQUAL(7, m_blob.properties().page_blob_sequence_number()); m_blob.set_sequence_number(azure::storage::sequence_number::increment(), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_EQUAL(8, m_blob.properties().page_blob_sequence_number()); CHECK_UTF8_EQUAL(U("en"), m_blob.properties().content_language()); m_blob.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_UTF8_EQUAL(U("tr,en"), m_blob.properties().content_language()); CHECK_EQUAL(8, m_blob.properties().page_blob_sequence_number()); m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_equal_condition(8), azure::storage::blob_request_options(), m_context); m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_less_than_or_equal_condition(8), azure::storage::blob_request_options(), m_context); m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_less_than_or_equal_condition(9), azure::storage::blob_request_options(), m_context); m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_less_than_condition(9), azure::storage::blob_request_options(), m_context); CHECK_THROW(m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_equal_condition(7), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); CHECK_THROW(m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_less_than_or_equal_condition(7), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); CHECK_THROW(m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_less_than_or_equal_condition(7), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); CHECK_THROW(m_blob.clear_pages(0, 512, azure::storage::access_condition::generate_if_sequence_number_less_than_condition(7), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); }
void container_test_base::check_public_access(azure::storage::blob_container_public_access_type access) { auto blob = m_container.get_block_blob_reference(_XPLATSTR("blob")); blob.upload_text(_XPLATSTR("test"), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); azure::storage::cloud_blob_container public_container(m_container.uri()); auto public_blob = public_container.get_blob_reference(blob.name()); if (access != azure::storage::blob_container_public_access_type::off) { public_blob.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); } else { CHECK_THROW(public_blob.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); } if (access == azure::storage::blob_container_public_access_type::container) { public_container.list_blobs_segmented(utility::string_t(), true, azure::storage::blob_listing_details::all, 0, azure::storage::continuation_token(), azure::storage::blob_request_options(), m_context); public_container.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); } else { CHECK_THROW(public_container.list_blobs_segmented(utility::string_t(), true, azure::storage::blob_listing_details::all, 0, azure::storage::continuation_token(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); CHECK_THROW(public_container.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); } auto perms = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK(access == perms.public_access()); }
TEST_FIXTURE(page_blob_test_base, page_blob_upload_with_invalid_size) { const size_t buffer_size = 2 * 1024 * 1024; azure::storage::blob_request_options options; CHECK_THROW(upload_and_download(m_blob, buffer_size, 0, buffer_size + 1, true, options, 0, false), azure::storage::storage_exception); CHECK_THROW(upload_and_download(m_blob, buffer_size, 0, buffer_size + 1, false, options, 0, false), azure::storage::storage_exception); CHECK_THROW(upload_and_download(m_blob, buffer_size, 1024, buffer_size - 1023, true, options, 0, false), azure::storage::storage_exception); CHECK_THROW(upload_and_download(m_blob, buffer_size, 1024, buffer_size - 1023, false, options, 0, false), azure::storage::storage_exception); }
int test_index_checking() { tested_sequence x; x.length(8); tested_sequence const & y = x; int z = 0; CHECK_THROW(z = y[32], std::range_error); CHECK_THROW(x[32] = z, std::range_error); return 0; }
TEST_FIXTURE(append_blob_test_base, append_block_size) { const size_t buffer_size = 8 * 1024 * 1024; std::vector<uint8_t> buffer; buffer.reserve(buffer_size); azure::storage::blob_request_options options; m_blob.create_or_replace(azure::storage::access_condition(), options, m_context); size_t sizes[] = { 1, 2, 1023, 1024, 4 * 1024, 1024 * 1024, azure::storage::protocol::max_block_size - 1, azure::storage::protocol::max_block_size }; size_t invalid_sizes[] = { azure::storage::protocol::max_block_size + 1, 6 * 1024 * 1024, 8 * 1024 * 1024 }; int64_t bytes_appended = 0; options.set_use_transactional_md5(true); for (size_t size : sizes) { buffer.resize(size); auto md5 = fill_buffer_and_get_md5(buffer, 0, size); auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, md5, azure::storage::access_condition(), options, m_context); CHECK_EQUAL(bytes_appended, offset); bytes_appended += size; } options.set_use_transactional_md5(false); for (size_t size : invalid_sizes) { buffer.resize(size); fill_buffer_and_get_md5(buffer, 0, size); auto stream = concurrency::streams::bytestream::open_istream(buffer); CHECK_THROW(m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition(), options, m_context), azure::storage::storage_exception); } }
TEST_FIXTURE(page_blob_test_base, page_blob_upload_with_nonseekable) { const size_t size = 6 * 1024 * 1024; azure::storage::blob_request_options options; CHECK_THROW(upload_and_download(m_blob, size, 0, 0, false, options, 3, false), std::logic_error); }
TEST_FIXTURE(block_blob_test_base, block_blob_write_stream_access_condition) { m_blob.upload_block_list(std::vector<azure::storage::block_list_item>(), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); auto missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob1")); CHECK_THROW(missing_blob.open_write(azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob2")); missing_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob3")); missing_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob4")); missing_blob.open_write(azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob5")); missing_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); m_blob.open_write(azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); auto stream = m_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); m_blob.open_write(azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); stream = m_blob.open_write(azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context); m_blob.upload_properties(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob6")); stream = missing_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context); missing_blob.upload_block_list(std::vector<azure::storage::block_list_item>(), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); stream = m_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified()), azure::storage::blob_request_options(), m_context); std::this_thread::sleep_for(std::chrono::seconds(1)); m_blob.upload_properties(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); }
TEST_FIXTURE(test_base, result_iterator_default_constructor) { azure::storage::result_iterator<int> iter; CHECK_THROW(*iter, std::runtime_error); CHECK(iter++ == iter); CHECK(++iter == iter); }
TEST_FIXTURE(test_base, result_iterator_fail_to_fetch_first_segment) { auto generator = [](const azure::storage::continuation_token &, size_t ) -> azure::storage::result_segment<int> { throw std::runtime_error("result_iterator first segment error"); }; CHECK_THROW(azure::storage::result_iterator<int>(generator, 0, 0), std::runtime_error); }
TEST_FIXTURE(RouterFixture, throws_choose_error_exception_when_unknown_type) { std::stringstream srcLine("__*fklsajdf"); this->repeat([&] { return srcLine.get(); }, 2); CHECK_THROW(this->router.choose(srcLine.get()), husky::types::TypeChooseError); }
TEST_FIXTURE(DefaultValues, RescaleLineDimensionMismatch) { typedef bgil::bgra8_pixel_t src_pixel_t; typedef bgil::rgba8_pixel_t dst_pixel_t; bgil::filter_triangle filter; { bgil::image<src_pixel_t, false> src(3, 3); bgil::image<dst_pixel_t, false> dst(7, 7); CHECK_THROW( bgil::rescale_rows( bgil::view(src), bgil::view(dst), filter ), std::runtime_error ); CHECK_THROW( bgil::rescale_cols( bgil::view(src), bgil::view(dst), filter ), std::runtime_error ); CHECK_NO_THROW( bgil::rescale( bgil::view(src), bgil::view(dst), filter ) ); } }
TEST_FIXTURE(page_blob_test_base, page_blob_file_upload) { azure::storage::blob_request_options options; options.set_store_blob_content_md5(true); utility::string_t md5_header; m_context.set_sending_request([&md5_header] (web::http::http_request& request, azure::storage::operation_context) { if (!request.headers().match(U("x-ms-blob-content-md5"), md5_header)) { md5_header.clear(); } }); temp_file invalid_file(1000); CHECK_THROW(m_blob.upload_from_file(invalid_file.path(), 0, azure::storage::access_condition(), options, m_context), azure::storage::storage_exception); temp_file file(1024); m_blob.upload_from_file(file.path(), 0, azure::storage::access_condition(), options, m_context); CHECK_UTF8_EQUAL(file.content_md5(), md5_header); m_context.set_sending_request(std::function<void(web::http::http_request &, azure::storage::operation_context)>()); temp_file file2(0); m_blob.download_to_file(file2.path(), azure::storage::access_condition(), options, m_context); concurrency::streams::container_buffer<std::vector<uint8_t>> original_file_buffer; auto original_file = concurrency::streams::file_stream<uint8_t>::open_istream(file.path()).get(); original_file.read_to_end(original_file_buffer).wait(); original_file.close().wait(); concurrency::streams::container_buffer<std::vector<uint8_t>> downloaded_file_buffer; auto downloaded_file = concurrency::streams::file_stream<uint8_t>::open_istream(file2.path()).get(); downloaded_file.read_to_end(downloaded_file_buffer).wait(); downloaded_file.close().wait(); CHECK_EQUAL(original_file_buffer.collection().size(), downloaded_file_buffer.collection().size()); CHECK_ARRAY_EQUAL(original_file_buffer.collection(), downloaded_file_buffer.collection(), (int)downloaded_file_buffer.collection().size()); m_blob.properties().set_content_md5(dummy_md5); m_blob.upload_properties(); options.set_retry_policy(azure::storage::no_retry_policy()); CHECK_THROW(m_blob.download_to_file(file2.path(), azure::storage::access_condition(), options, m_context), azure::storage::storage_exception); }
/** * Loads data from configuration file. */ void Config::load(const std::string &filename) { CHECK_THROW(filename.size()); m_configFile = filename; setPath("/"); std::ifstream ifs(filename.c_str(), std::ios::in); if (!ifs) { logWarning( "No config file found, using default configuration " "values." ); return; } while (ifs.good()) { std::string line; std::getline(ifs, line); // Remove preceeding whitespace boost::algorithm::trim(line); if (line.length() < 2) { continue; } // Directories if ((*(line.begin()) == '[') && (*(--line.end()) == ']')) { std::string dir; dir += line.substr(1, line.length() - 2); setPath("/" + dir); logTrace(TRACE_CONFIG, boost::format("Reading: got path=%s") % dir ); continue; } // Values size_t pos = line.find('=', 0); if (pos != std::string::npos) { std::string name = line.substr(0, pos); std::string value = line.substr(pos + 1); m_values[m_curPath + name] = value; logTrace(TRACE_CONFIG, boost::format( "Reading: got key=%s " "value=%s curpath=%s" ) % name % value % m_curPath ); continue; } } setPath("/"); }
TEST_FIXTURE(append_blob_test_base, append_block_append_position_condition) { const size_t buffer_size = 64 * 1024; std::vector<uint8_t> buffer; buffer.resize(buffer_size); azure::storage::blob_request_options options; options.set_use_transactional_md5(true); m_blob.create_or_replace(azure::storage::access_condition(), options, m_context); int64_t invalid_appendpos[] = { 1, 2, buffer_size, buffer_size + 1, std::numeric_limits<int64_t>::max() }; for (int64_t appendpos : invalid_appendpos) { auto md5 = fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); CHECK_THROW(m_blob.append_block(stream, md5, azure::storage::access_condition::generate_if_append_position_equal_condition(appendpos), options, m_context), azure::storage::storage_exception); } for (int16_t i = 0; i < 3; i++) { auto md5 = fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, md5, azure::storage::access_condition::generate_if_append_position_equal_condition(i * buffer_size), options, m_context); CHECK_EQUAL(offset, i * buffer_size); CHECK_EQUAL(i + 1, m_blob.properties().append_blob_committed_block_count()); } int64_t invalid_appendpos2[] = { buffer_size * 3 - 1, buffer_size * 3 + 1}; for (int64_t appendpos : invalid_appendpos2) { auto md5 = fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); CHECK_THROW(m_blob.append_block(stream, md5, azure::storage::access_condition::generate_if_append_position_equal_condition(appendpos), options, m_context), azure::storage::storage_exception); } auto md5 = fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); CHECK_EQUAL(3 * buffer_size, m_blob.append_block(stream, md5, azure::storage::access_condition::generate_if_append_position_equal_condition(3 * buffer_size), options, m_context)); CHECK_EQUAL(4, m_blob.properties().append_blob_committed_block_count()); m_blob.delete_blob(); }
TEST_FIXTURE(append_blob_test_base, append_blob_upload_max_size_condition) { const size_t buffer_size = 1024 * 1024; std::vector<uint8_t> buffer; buffer.resize(buffer_size); fill_buffer_and_get_md5(buffer); concurrency::streams::istream stream = concurrency::streams::bytestream::open_istream(buffer); auto condition = azure::storage::access_condition::generate_if_max_size_less_than_or_equal_condition(512); CHECK_THROW(m_blob.upload_from_stream(stream, condition, azure::storage::blob_request_options(), m_context), std::invalid_argument); }
/** * Changes current active directory. */ void Config::setPath(const std::string &dir) { CHECK_THROW(dir.size()); if (*(dir.begin()) == '/') { m_curPath = dir; } else { m_curPath += dir; } if (*--m_curPath.end() != '/') { m_curPath += '/'; } }
TEST_FIXTURE(block_blob_test_base, blob_read_stream_etag_lock) { azure::storage::blob_request_options options; options.set_stream_read_size_in_bytes(1 * 1024 * 1024); std::vector<uint8_t> buffer; buffer.resize(2 * 1024 * 1024); fill_buffer_and_get_md5(buffer); m_blob.upload_from_stream(concurrency::streams::bytestream::open_istream(buffer), azure::storage::access_condition(), options, m_context); auto stream = m_blob.open_read(azure::storage::access_condition(), options, m_context); m_blob.upload_metadata(azure::storage::access_condition(), options, m_context); CHECK_THROW(stream.read().wait(), azure::storage::storage_exception); stream.close().wait(); auto condition = azure::storage::access_condition::generate_if_match_condition(_XPLATSTR("*")); stream = m_blob.open_read(condition, options, m_context); m_blob.upload_metadata(azure::storage::access_condition(), options, m_context); CHECK_THROW(stream.read().wait(), azure::storage::storage_exception); stream.close().wait(); }
SearchTree::Node<bool>* parseBinary( SearchContext& sc, std::ifstream& i ) { uint8_t opcode = Utils::getVal<uint8_t>(i); SearchTree::Node<bool>* node; switch(opcode) { case 1: return new ContainsString(sc, i); } CHECK_THROW(0); }
int test_exception_in_copy_constructor() { expected_calls f(tested_allocation_traits::freebuf_calls); { tested_sequence x; x.length(8); f.reset(); expected_calls a(tested_allocation_traits::allocbuf_calls); tested_allocation_traits::allocbuf_calls.failure_countdown(1); CHECK_THROW(tested_sequence y(x), testing_exception); FAIL_RETURN_IF_NOT(a.expect(1), a); } FAIL_RETURN_IF_NOT(f.expect(1), f); return 0; }
/** * Saves data into configuration file. */ void Config::save(const std::string &filename) const { CHECK_THROW(filename.size()); std::ofstream ofs(filename.c_str(), std::ios::out); if (!ofs) { logError( boost::format("Failed to open config file '%s'" " for writing.") % filename ); return; } // root dir values copied here and written separately std::vector<std::pair<std::string, std::string> > rootValues; std::string curpath = "/"; std::string wrpath = ""; for (CIter i = m_values.begin(); i != m_values.end(); ++i) { size_t pos = (*i).first.find_last_of('/'); if (pos == 0) { rootValues.push_back(*i); continue; } std::string key = (*i).first.substr(pos + 1); std::string path = (*i).first.substr(1, pos > 0 ? pos - 1 :pos); std::string value = (*i).second; logTrace(TRACE_CONFIG, boost::format("Writing: Key=%s Value=%s Path=%s") % key % value % path ); if (path != wrpath) { // Path not written yet ofs << "[" << path << "]\n"; wrpath = path; } ofs << key << "=" << value << std::endl; } // root keys are written in section [] ofs << "[]" << std::endl; while (rootValues.size()) { ofs << rootValues.back().first.substr(1) << "="; ofs << rootValues.back().second << std::endl; rootValues.pop_back(); } }
void test_base64() { // take some static hex data and dump it using base64 encoding, then decode it again. const unsigned char rand1data[42] = { 0x16,0x35,0xCA,0x03,0x90,0x6B,0x47,0x11,0x85,0x02,0xE7,0x40,0x9E,0x3A,0xCE,0x43, 0x0C,0x57,0x3E,0x35,0xE7,0xA6,0xB2,0x37,0xEC,0x6D,0xF6,0x68,0xF6,0x0E,0x74,0x0C, 0x44,0x3F,0x0F,0xD4,0xAA,0x56,0xE5,0x2F,0x58,0xCC }; std::string rand1 = ARRAY_AS_STRING(rand1data); std::string rand1base64 = stx::string::base64_encode(rand1); CHECK( rand1base64 == "FjXKA5BrRxGFAudAnjrOQwxXPjXnprI37G32aPYOdAxEPw/UqlblL1jM" ); CHECK( stx::string::base64_decode(rand1base64, 1) == rand1 ); // check line-splitting std::string rand1base64lines = stx::string::base64_encode(rand1, 16); CHECK( rand1base64lines == "FjXKA5BrRxGFAudA\n" "njrOQwxXPjXnprI3\n" "7G32aPYOdAxEPw/U\n" "qlblL1jM" ); // take three random binary data string with different sizes and run // the base64 encoding->decoding->checking drill. std::string rand12 = stx::string::random_binary(12); CHECK( stx::string::base64_decode( stx::string::base64_encode(rand12) , 1) == rand12 ); std::string rand13 = stx::string::random_binary(13); CHECK( stx::string::base64_decode( stx::string::base64_encode(rand13) , 1) == rand13 ); std::string rand14 = stx::string::random_binary(14); CHECK( stx::string::base64_decode( stx::string::base64_encode(rand14) , 1) == rand14 ); // run a larger set of random tests for (unsigned int ti = 0; ti < 1000; ++ti) { unsigned int randlen = ti; // rand() % 1000; std::string randstr = stx::string::random_binary(randlen); CHECK( stx::string::base64_decode( stx::string::base64_encode(randstr) , 1) == randstr ); } CHECK_THROW( stx::string::base64_decode("FjXKA5!!RxGFAudA", 1), std::runtime_error ); }
int test_exception_in_assignment() { expected_calls f(tested_allocation_traits::freebuf_calls); { tested_sequence x; x.length(2); tested_sequence y; y.length(3); expected_calls a(tested_allocation_traits::allocbuf_calls); f.reset(); tested_allocation_traits::allocbuf_calls.failure_countdown(1); CHECK_THROW(y = x, testing_exception); FAIL_RETURN_IF_NOT(a.expect(1), a); FAIL_RETURN_IF_NOT(f.expect(0), f); CHECK_EQUAL(CORBA::ULong(3), y.length()); } FAIL_RETURN_IF_NOT(f.expect(2), f); return 0; }
TEST_FIXTURE(page_blob_test_base, page_blob_upload_maximum_execution_time) { std::chrono::seconds duration(10); std::vector<uint8_t> buffer; buffer.resize(2 * 1024 * 1024); azure::storage::blob_request_options options; options.set_maximum_execution_time(duration); options.set_stream_write_size_in_bytes(buffer.size() / 2); m_context.set_response_received([duration] (web::http::http_request&, const web::http::http_response&, azure::storage::operation_context) { std::this_thread::sleep_for(duration); }); CHECK_THROW(m_blob.upload_from_stream(concurrency::streams::bytestream::open_istream(std::move(buffer)), 0, azure::storage::access_condition(), options, m_context), azure::storage::storage_exception); CHECK_EQUAL(2U, m_context.request_results().size()); m_context.set_response_received(std::function<void(web::http::http_request &, const web::http::http_response&, azure::storage::operation_context)>()); }
void test_hexdump() { // take hex data and dump it into a string, then parse back into array const unsigned char hexdump[8] = { 0x8D,0xE2,0x85,0xD4,0xBF,0x98,0xE6,0x03 }; std::string hexdata = ARRAY_AS_STRING(hexdump); std::string hexstring = stx::string::hexdump(hexdata); CHECK( hexstring == "8DE285D4BF98E603" ); CHECK( stx::string::hexdump(hexdump, sizeof(hexdump)) == "8DE285D4BF98E603" ); std::string hexparsed = stx::string::parse_hexdump(hexstring); CHECK( hexparsed == hexdata ); // dump random binary string into hex and parse it back std::string rand1 = stx::string::random_binary(42); CHECK( stx::string::parse_hexdump( stx::string::hexdump(rand1) ) == rand1 ); // take the first hex list and dump it into source code format, then // compare it with correct data (which was also dumped with // hexdump_sourcecode()) std::string hexsource = stx::string::hexdump_sourcecode(hexdata, "abc"); const unsigned char hexsourcecmp[65] = { 0x63,0x6F,0x6E,0x73,0x74,0x20,0x63,0x68,0x61,0x72,0x20,0x61,0x62,0x63,0x5B,0x38, 0x5D,0x20,0x3D,0x20,0x7B,0x0A,0x30,0x78,0x38,0x44,0x2C,0x30,0x78,0x45,0x32,0x2C, 0x30,0x78,0x38,0x35,0x2C,0x30,0x78,0x44,0x34,0x2C,0x30,0x78,0x42,0x46,0x2C,0x30, 0x78,0x39,0x38,0x2C,0x30,0x78,0x45,0x36,0x2C,0x30,0x78,0x30,0x33,0x0A,0x7D,0x3B, 0x0A }; CHECK( hexsource == ARRAY_AS_STRING(hexsourcecmp) ); // test parse_hexdump with illegal string CHECK_THROW( stx::string::parse_hexdump("illegal"), std::runtime_error); }
TEST_FIXTURE(page_blob_test_base, page_blob_write_stream_access_condition) { m_blob.create(0, 0, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); auto missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob1")); CHECK_THROW(missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob2")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob3")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob4")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob5")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); }
TEST_FIXTURE(append_blob_test_base, append_block) { const size_t buffer_size = 16 * 1024; std::vector<uint8_t> buffer; buffer.resize(buffer_size); azure::storage::blob_request_options options; utility::string_t md5_header; m_context.set_sending_request([&md5_header](web::http::http_request& request, azure::storage::operation_context) { if (!request.headers().match(web::http::header_names::content_md5, md5_header)) { md5_header.clear(); } }); m_blob.create_or_replace(azure::storage::access_condition(), options, m_context); options.set_use_transactional_md5(false); for (uint16_t i = 0; i < 3; ++i) { fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition(), options, m_context); CHECK_UTF8_EQUAL(utility::string_t(), md5_header); CHECK_EQUAL(i * buffer_size, offset); CHECK_EQUAL(i + 1, m_blob.properties().append_blob_committed_block_count()); } options.set_use_transactional_md5(false); for (uint16_t i = 3; i < 6; ++i) { auto md5 = fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, md5, azure::storage::access_condition(), options, m_context); CHECK_UTF8_EQUAL(md5, md5_header); CHECK_EQUAL(i * buffer_size, offset); CHECK_EQUAL(i + 1, m_blob.properties().append_blob_committed_block_count()); } options.set_use_transactional_md5(true); for (uint16_t i = 6; i < 9; ++i) { auto md5 = fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition(), options, m_context); CHECK_UTF8_EQUAL(md5, md5_header); CHECK_EQUAL(i * buffer_size, offset); CHECK_EQUAL(i + 1, m_blob.properties().append_blob_committed_block_count()); } // block stream with length = 0 options.set_use_transactional_md5(true); fill_buffer_and_get_md5(buffer); auto stream1 = concurrency::streams::bytestream::open_istream(buffer); stream1.seek(buffer.size()); CHECK_THROW(m_blob.append_block(stream1, utility::string_t(), azure::storage::access_condition(), options, m_context), azure::storage::storage_exception); options.set_use_transactional_md5(true); fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); CHECK_THROW(m_blob.append_block(stream, dummy_md5, azure::storage::access_condition(), options, m_context), azure::storage::storage_exception); CHECK_UTF8_EQUAL(dummy_md5, md5_header); m_context.set_sending_request(std::function<void(web::http::http_request &, azure::storage::operation_context)>()); }
TEST_FIXTURE(HashDictFixture, get_empty) { CHECK(testDict.empty()); CHECK_THROW(testDict.get(1), std::logic_error); }
TEST_FIXTURE(append_blob_test_base, append_block_max_size_condition) { const size_t buffer_size = 64 * 1024; std::vector<uint8_t> buffer; buffer.resize(buffer_size); fill_buffer_and_get_md5(buffer); azure::storage::blob_request_options options; options.set_use_transactional_md5(false); int64_t max_sizes1[] = {1, 1024, buffer_size - 1}; for (int64_t max_size : max_sizes1) { m_blob.create_or_replace(azure::storage::access_condition(), options, m_context); auto stream = concurrency::streams::bytestream::open_istream(buffer); CHECK_THROW(m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition::generate_if_max_size_less_than_or_equal_condition(max_size), options, m_context), azure::storage::storage_exception); m_blob.delete_blob(); } int64_t max_sizes2[] = { buffer_size, 2 * buffer_size, std::numeric_limits<int64_t>::max() }; for (int64_t max_size : max_sizes2) { m_blob.create_or_replace(azure::storage::access_condition(), options, m_context); auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition::generate_if_max_size_less_than_or_equal_condition(max_size), options, m_context); CHECK_EQUAL(0, offset); m_blob.delete_blob(); } int64_t blob_size = 0; int block_count = 0; m_blob.create_or_replace(azure::storage::access_condition(), options, m_context); for (uint16_t i = 0; i < 3; ++i) { fill_buffer_and_get_md5(buffer); auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition(), options, m_context); block_count++; CHECK_EQUAL(blob_size, offset); CHECK_EQUAL(block_count, m_blob.properties().append_blob_committed_block_count()); blob_size += buffer.size(); } int64_t max_sizes3[] = { 3 * buffer_size - 1, 3 * buffer_size, 3 * buffer_size + 1, 4 * buffer_size - 1 }; for (int64_t max_size : max_sizes3) { auto stream = concurrency::streams::bytestream::open_istream(buffer); CHECK_THROW(m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition::generate_if_max_size_less_than_or_equal_condition(max_size), options, m_context), azure::storage::storage_exception); } int64_t max_sizes4[] = { 4 * buffer_size, std::numeric_limits<int64_t>::max() }; for (int64_t max_size : max_sizes4) { auto stream = concurrency::streams::bytestream::open_istream(buffer); int64_t offset = m_blob.append_block(stream, utility::string_t(), azure::storage::access_condition::generate_if_max_size_less_than_or_equal_condition(max_size), options, m_context); block_count++; CHECK_EQUAL(blob_size, offset); CHECK_EQUAL(block_count, m_blob.properties().append_blob_committed_block_count()); blob_size += buffer.size(); } m_blob.delete_blob(); }