#include <string>
#include <utility>
#include <vector>
#include "gmock/gmock.h"
#include "test/test_fixture.h"
#include "test/unit_spirv.h"
namespace spvtools {
namespace {
using ::testing::Eq;
using RoundTripLiteralsTest =
spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;
static const bool kSwapEndians[] = {false, true};
TEST_P(RoundTripLiteralsTest, Sample) {
for (bool endian_swap : kSwapEndians) {
EXPECT_THAT(
EncodeAndDecodeSuccessfully(GetParam(), SPV_BINARY_TO_TEXT_OPTION_NONE,
SPV_TEXT_TO_BINARY_OPTION_NONE,
SPV_ENV_UNIVERSAL_1_0, endian_swap),
Eq(GetParam()));
}
}
INSTANTIATE_TEST_SUITE_P(
StringLiterals, RoundTripLiteralsTest,
::testing::ValuesIn(std::vector<std::string>{
"OpName %1 \"\"\n",
"OpName %1 \"foo\"\n",
"OpName %1 \"foo bar\"\n",
"OpName %1 \"foo\tbar\"\n",
"OpName %1 \"\tfoo\"\n",
"OpName %1 \" foo\"\n",
"OpName %1 \"foo \"\n",
"OpName %1 \"foo\t\"\n",
"OpName %1 \"foo\nbar\"\n",
"OpName %1 \"\nfoo\nbar\"\n",
"OpName %1 \"\n\n\nfoo\nbar\"\n",
"OpName %1 \"\\\"foo\nbar\\\"\"\n",
"OpName %1 \"\\\\foo\nbar\\\\\"\n",
"OpName %1 \"\xE4\xBA\xB2\"\n",
}));
using RoundTripSpecialCaseLiteralsTest = spvtest::TextToBinaryTestBase<
::testing::TestWithParam<std::pair<std::string, std::string>>>;
TEST_P(RoundTripSpecialCaseLiteralsTest, Sample) {
for (bool endian_swap : kSwapEndians) {
EXPECT_THAT(EncodeAndDecodeSuccessfully(std::get<0>(GetParam()),
SPV_BINARY_TO_TEXT_OPTION_NONE,
SPV_TEXT_TO_BINARY_OPTION_NONE,
SPV_ENV_UNIVERSAL_1_0, endian_swap),
Eq(std::get<1>(GetParam())));
}
}
INSTANTIATE_TEST_SUITE_P(
StringLiterals, RoundTripSpecialCaseLiteralsTest,
::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
{"OpName %1 \"\\foo\"\n", "OpName %1 \"foo\"\n"},
{"OpName %1 \"\\\nfoo\"\n", "OpName %1 \"\nfoo\"\n"},
{"OpName %1 \"\\\xE4\xBA\xB2\"\n", "OpName %1 \"\xE4\xBA\xB2\"\n"},
}));
}
}