#include "tile/base/encoding/hex.h"

#include "gtest/gtest.h"

#include "tile/testing/internal/random_string.h"

namespace tile {
const char Hex123456FF[] = "\x12\x34\x56\xFF";

TEST(Hex, Default)
{
    EXPECT_EQ("123456ff", EncodeHex(Hex123456FF));
    EXPECT_EQ("123456FF", EncodeHex(Hex123456FF, true));
    EXPECT_EQ(Hex123456FF, *DecodeHex("123456ff"));
    EXPECT_EQ(Hex123456FF, *DecodeHex("123456FF"));
}

TEST(Hex, Random)
{
    std::string random_str;
    std::string encoded;
    std::string decoded;
    for (int i = 0; i != 1000; ++i) {
        testing::RandomString(&random_str);
        EncodeHex(random_str, &encoded);
        ASSERT_TRUE(DecodeHex(encoded, &decoded));
        EXPECT_EQ(random_str, decoded);
    }
}

}// namespace tile
