This source file includes following definitions.
- checkKeyPath
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "config.h"
#include "modules/indexeddb/IDBKeyPath.h"
#include "bindings/v8/IDBBindingUtilities.h"
#include "bindings/v8/SerializedScriptValue.h"
#include "modules/indexeddb/IDBKey.h"
#include "wtf/Vector.h"
#include <gtest/gtest.h>
using namespace WebCore;
namespace {
void checkKeyPath(const String& keyPath, const Vector<String>& expected, int parserError)
{
IDBKeyPath idbKeyPath(keyPath);
ASSERT_EQ(idbKeyPath.type(), IDBKeyPath::StringType);
ASSERT_EQ(idbKeyPath.isValid(), (parserError == IDBKeyPathParseErrorNone));
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);
}
}