BOOST_FIXTURE_TEST_CASE(TestListDir, FileOpenFixture) { std::string parentPath = tmpPath.string(); std::vector<std::string> files = ListDir(parentPath, "txt"); BOOST_TEST_REQUIRE(files.size() == 3u); for(const std::string& file : files) { BOOST_REQUIRE(bfs::exists(file)); BOOST_REQUIRE(bfs::path(file).is_absolute()); // Filepath must be utf8 encoded BOOST_REQUIRE(isValidUTF8(file)); bfs::path filePath(file); // String result must still be utf8 BOOST_REQUIRE(isValidUTF8(filePath.string())); // Scopes for auto-close { // path input bnw::ifstream sFile(filePath); BOOST_REQUIRE(sFile); std::string content; BOOST_REQUIRE(sFile >> content); BOOST_TEST_REQUIRE(content == "OK"); } { // string input bnw::ifstream sFile(file); BOOST_REQUIRE(sFile); std::string content; BOOST_REQUIRE(sFile >> content); BOOST_TEST_REQUIRE(content == "OK"); } { // Memory mapped file boost::iostreams::mapped_file_source mmapFile; mmapFile.open(bfs::path(file)); BOOST_TEST_REQUIRE(mmapFile.is_open()); using MMStream = boost::iostreams::stream<boost::iostreams::mapped_file_source>; MMStream map(mmapFile); std::string content; BOOST_REQUIRE(map >> content); BOOST_TEST_REQUIRE(content == "OK"); } } }
BOOST_AUTO_TEST_CASE_TEMPLATE( return_error_message_if_version_is_not_v1, T, all_message_types) { auto const header = protocol::ofp_header{ protocol::OFP_VERSION + 1, T::type(), T::min_length(), random_xid() }; auto const error_msg = T::validate_header(header); BOOST_TEST_REQUIRE(bool(error_msg), "should not be nullptr"); BOOST_TEST(error_msg == "invalid version"_sr); }
BOOST_AUTO_TEST_CASE_TEMPLATE( return_error_message_if_no_hasmask_and_oxm_length_is_greater_than_oxm_value_size , T, all_oxm_match_field_types) { constexpr auto payload_length = T::min_length() - sizeof(std::uint32_t); auto const header = std::uint32_t(((T::oxm_type() << 9) | 0x0000 | payload_length) + 1); auto const error_msg = T::validate_header(header); BOOST_TEST_REQUIRE(bool(error_msg), "should not be nullptr"); BOOST_TEST(error_msg == "invalid oxm length"_sr); }
BOOST_AUTO_TEST_CASE_TEMPLATE( return_error_message_if_length_is_less_than_ofp_struct_size , T, all_message_types) { auto const header = protocol::ofp_header{ protocol::OFP_VERSION, T::type(), T::min_length() - 1, random_xid() }; auto const error_msg = T::validate_header(header); BOOST_TEST_REQUIRE(bool(error_msg), "should not be nullptr"); BOOST_TEST(error_msg == "invalid message length"_sr); }
BOOST_AUTO_TEST_CASE_TEMPLATE( return_error_message_if_type_is_incorrect, T, all_action_types) { auto const header = protocol::ofp_action_header{ T::type() + 1, T::min_length() , { random_pad(), random_pad(), random_pad(), random_pad() } }; auto const error_msg = T::validate_header(header); BOOST_TEST_REQUIRE(bool(error_msg), "should not be nullptr"); BOOST_TEST(error_msg == "invalid action type"_sr); }
BOOST_AUTO_TEST_CASE_TEMPLATE( return_error_message_if_length_is_greater_than_ofp_struct_size_for , FixedLengthMessage, fixed_length_message_types) { auto const header = protocol::ofp_header{ protocol::OFP_VERSION , FixedLengthMessage::type() , FixedLengthMessage::min_length() + 1 , random_xid() }; auto const error_msg = FixedLengthMessage::validate_header(header); BOOST_TEST_REQUIRE(bool(error_msg), "should not be nullptr"); BOOST_TEST(error_msg == "invalid message length"_sr); }
BOOST_AUTO_TEST_CASE_TEMPLATE( return_error_message_if_oxm_field_is_incorrect , T, all_oxm_match_field_types) { constexpr auto payload_length = T::min_length() - sizeof(std::uint32_t); auto const hasmask = random_hasmask(); auto const header = std::uint32_t( (std::uint32_t(T::oxm_class()) << 16) | (std::uint32_t(T::oxm_field() + 1) << 9) | (hasmask ? 0x0100 : 0x0000) | (hasmask ? payload_length * 2 : payload_length)); auto const error_msg = T::validate_header(header); BOOST_TEST_REQUIRE(bool(error_msg), "should not be nullptr"); BOOST_TEST(error_msg == "invalid oxm field"_sr); }
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test1, Number ) { BOOST_TEST( 6 == (int)Number::value ); BOOST_TEST_REQUIRE( 2 <= (int)Number::value ); BOOST_TEST( 3 == (int)Number::value ); }