Hash :
c7be82ae
Author :
Date :
2015-06-01T14:14:04
Change behaviour of string_utils, also fix file io. File IO tested manually in a follow-up patch. BUG=angleproject:998 Change-Id: I0bfa778d1787cdedfbf3cd68cd134477e6dcd23c Reviewed-on: https://chromium-review.googlesource.com/274030 Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// string_utils_unittests:
// Unit tests for the string utils.
//
#include "string_utils.h"
#include <gtest/gtest.h>
using namespace angle;
namespace
{
// Basic functionality tests for SplitString
TEST(StringUtilsTest, SplitStringBasic)
{
std::string testString("AxBxCxxxDExxFGHx");
std::vector<std::string> tokens;
SplitString(testString, 'x', &tokens);
ASSERT_EQ(5u, tokens.size());
EXPECT_EQ("A", tokens[0]);
EXPECT_EQ("B", tokens[1]);
EXPECT_EQ("C", tokens[2]);
EXPECT_EQ("DE", tokens[3]);
EXPECT_EQ("FGH", tokens[4]);
}
// Basic functionality tests for SplitStringAlongWhitespace
TEST(StringUtilsTest, SplitStringAlongWhitespaceBasic)
{
std::string testString("A B\nC\r\tDE\v\fFGH \t\r\n");
std::vector<std::string> tokens;
SplitStringAlongWhitespace(testString, &tokens);
ASSERT_EQ(5u, tokens.size());
EXPECT_EQ("A", tokens[0]);
EXPECT_EQ("B", tokens[1]);
EXPECT_EQ("C", tokens[2]);
EXPECT_EQ("DE", tokens[3]);
EXPECT_EQ("FGH", tokens[4]);
}
// Basic functionality tests for HexStringToUInt
TEST(StringUtilsTest, HexStringToUIntBasic)
{
unsigned int uintValue;
std::string emptyString;
ASSERT_FALSE(HexStringToUInt(emptyString, &uintValue));
std::string testStringA("0xBADF00D");
ASSERT_TRUE(HexStringToUInt(testStringA, &uintValue));
EXPECT_EQ(0xBADF00Du, uintValue);
std::string testStringB("0xBADFOOD");
EXPECT_FALSE(HexStringToUInt(testStringB, &uintValue));
std::string testStringC("BADF00D");
EXPECT_TRUE(HexStringToUInt(testStringC, &uintValue));
EXPECT_EQ(0xBADF00Du, uintValue);
std::string testStringD("0x BADF00D");
EXPECT_FALSE(HexStringToUInt(testStringD, &uintValue));
}
// Note: ReadFileToString is harder to test
}