IDBKeyPathTest.cpp [plain text]
#include "config.h"
#include "IDBKeyPath.h"
#include <gtest/gtest.h>
#include <wtf/Vector.h>
#if ENABLE(INDEXED_DATABASE)
using namespace WebCore;
namespace {
void checkKeyPath(const String& keyPath, const Vector<String>& expected, int parserError)
{
IDBKeyPathParseError error;
Vector<String> keyPathElements;
IDBParseKeyPath(keyPath, keyPathElements, error);
ASSERT_EQ(parserError, error);
if (error != IDBKeyPathParseErrorNone)
return;
ASSERT_EQ(expected.size(), keyPathElements.size());
for (size_t i = 0; i < expected.size(); ++i)
ASSERT_TRUE(expected[i] == keyPathElements[i]) << i;
}
TEST(IDBKeyPathTest, ValidKeyPath0)
{
Vector<String> expected;
String keyPath("");
checkKeyPath(keyPath, expected, 0);
}
TEST(IDBKeyPathTest, ValidKeyPath1)
{
Vector<String> expected;
String keyPath("foo");
expected.append(String("foo"));
checkKeyPath(keyPath, expected, 0);
}
TEST(IDBKeyPathTest, ValidKeyPath2)
{
Vector<String> expected;
String keyPath("foo.bar.baz");
expected.append(String("foo"));
expected.append(String("bar"));
expected.append(String("baz"));
checkKeyPath(keyPath, expected, 0);
}
TEST(IDBKeyPathTest, InvalidKeyPath0)
{
Vector<String> expected;
String keyPath(" ");
checkKeyPath(keyPath, expected, 1);
}
TEST(IDBKeyPathTest, InvalidKeyPath1)
{
Vector<String> expected;
String keyPath("+foo.bar.baz");
checkKeyPath(keyPath, expected, 1);
}
TEST(IDBKeyPathTest, InvalidKeyPath2)
{
Vector<String> expected;
String keyPath("foo bar baz");
expected.append(String("foo"));
checkKeyPath(keyPath, expected, 2);
}
TEST(IDBKeyPathTest, InvalidKeyPath3)
{
Vector<String> expected;
String keyPath("foo .bar .baz");
expected.append(String("foo"));
checkKeyPath(keyPath, expected, 2);
}
TEST(IDBKeyPathTest, InvalidKeyPath4)
{
Vector<String> expected;
String keyPath("foo. bar. baz");
expected.append(String("foo"));
checkKeyPath(keyPath, expected, 3);
}
TEST(IDBKeyPathTest, InvalidKeyPath5)
{
Vector<String> expected;
String keyPath("foo..bar..baz");
expected.append(String("foo"));
checkKeyPath(keyPath, expected, 3);
}
}
#endif // ENABLE(INDEXED_DATABASE)