// This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. #include "FuzzerFnAdapter.h" #include "gtest/gtest-spi.h" #include "gtest/gtest.h" namespace fuzzer { namespace impl { template bool Unpack(std::tuple *Tuple, std::initializer_list data) { std::vector V(data); return Unpack(V.data(), V.size(), Tuple); } TEST(Unpack, Bool) { std::tuple T; EXPECT_TRUE(Unpack(&T, {1})); EXPECT_TRUE(std::get<0>(T)); EXPECT_TRUE(Unpack(&T, {0})); EXPECT_FALSE(std::get<0>(T)); EXPECT_FALSE(Unpack(&T, {})); } TEST(Unpack, BoolBool) { std::tuple T; EXPECT_TRUE(Unpack(&T, {1, 0})); EXPECT_TRUE(std::get<0>(T)); EXPECT_FALSE(std::get<1>(T)); EXPECT_TRUE(Unpack(&T, {0, 1})); EXPECT_FALSE(std::get<0>(T)); EXPECT_TRUE(std::get<1>(T)); EXPECT_FALSE(Unpack(&T, {})); EXPECT_FALSE(Unpack(&T, {10})); } TEST(Unpack, BoolInt) { std::tuple T; EXPECT_TRUE(Unpack(&T, {1, 16, 2, 0, 0})); EXPECT_TRUE(std::get<0>(T)); EXPECT_EQ(528, std::get<1>(T)); EXPECT_FALSE(Unpack(&T, {1, 2})); } TEST(Unpack, Vector) { std::tuple> T; const auto &V = std::get<0>(T); EXPECT_FALSE(Unpack(&T, {})); EXPECT_TRUE(Unpack(&T, {0})); EXPECT_EQ(0ul, V.size()); EXPECT_TRUE(Unpack(&T, {0, 1, 2, 3})); EXPECT_EQ(0ul, V.size()); EXPECT_TRUE(Unpack(&T, {2})); EXPECT_EQ(0ul, V.size()); EXPECT_TRUE(Unpack(&T, {2, 3})); EXPECT_EQ(1ul, V.size()); EXPECT_EQ(3, V[0]); EXPECT_TRUE(Unpack(&T, {2, 9, 8})); EXPECT_EQ(2ul, V.size()); EXPECT_EQ(9, V[0]); EXPECT_EQ(8, V[1]); } TEST(Unpack, String) { std::tuple T; const auto &S = std::get<0>(T); EXPECT_TRUE(Unpack(&T, {2, 3})); EXPECT_EQ(1ul, S.size()); EXPECT_EQ(3, S[0]); } template bool UnpackAndApply(Fn F, std::initializer_list Data) { std::vector V(Data); return UnpackAndApply(F, V.data(), V.size()); } static void fnBool(bool b) { EXPECT_TRUE(b); } TEST(Apply, Bool) { EXPECT_FALSE(UnpackAndApply(fnBool, {})); EXPECT_TRUE(UnpackAndApply(fnBool, {1})); EXPECT_NONFATAL_FAILURE(UnpackAndApply(fnBool, {0}), "Actual: false\nExpected: true"); } static void fnInt(int i) { EXPECT_EQ(42, i); } TEST(Apply, Int) { EXPECT_FALSE(UnpackAndApply(fnInt, {})); EXPECT_TRUE(UnpackAndApply(fnInt, {42, 0, 0, 0})); EXPECT_NONFATAL_FAILURE(UnpackAndApply(fnInt, {10, 0, 0, 0}), "Actual: 10\nExpected: 42"); } } // namespace impl } // namespace fuzzer