Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/tests/gtest/TestDafsa.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/Dafsa.h"
8
#include "gtest/gtest.h"
9
10
#include "nsString.h"
11
12
using mozilla::Dafsa;
13
14
namespace dafsa_test_1 {
15
#include "dafsa_test_1.inc" // kDafsa
16
}
17
18
TEST(Dafsa, Constructor)
19
0
{
20
0
  Dafsa d(dafsa_test_1::kDafsa);
21
0
}
22
23
TEST(Dafsa, StringsFound)
24
0
{
25
0
  Dafsa d(dafsa_test_1::kDafsa);
26
0
27
0
  int tag = d.Lookup(NS_LITERAL_CSTRING("foo.bar.baz"));
28
0
  EXPECT_EQ(tag, 1);
29
0
30
0
  tag = d.Lookup(NS_LITERAL_CSTRING("a.test.string"));
31
0
  EXPECT_EQ(tag, 0);
32
0
33
0
  tag = d.Lookup(NS_LITERAL_CSTRING("a.test.string2"));
34
0
  EXPECT_EQ(tag, 2);
35
0
36
0
  tag = d.Lookup(NS_LITERAL_CSTRING("aaaa"));
37
0
  EXPECT_EQ(tag, 4);
38
0
}
39
40
TEST(Dafsa, StringsNotFound)
41
0
{
42
0
  Dafsa d(dafsa_test_1::kDafsa);
43
0
44
0
  // Matches all but last letter.
45
0
  int tag = d.Lookup(NS_LITERAL_CSTRING("foo.bar.ba"));
46
0
  EXPECT_EQ(tag, Dafsa::kKeyNotFound);
47
0
48
0
  // Matches prefix with extra letter.
49
0
  tag = d.Lookup(NS_LITERAL_CSTRING("a.test.strings"));
50
0
  EXPECT_EQ(tag, Dafsa::kKeyNotFound);
51
0
52
0
  // Matches small portion.
53
0
  tag = d.Lookup(NS_LITERAL_CSTRING("a.test"));
54
0
  EXPECT_EQ(tag, Dafsa::kKeyNotFound);
55
0
56
0
  // Matches repeating pattern with extra letters.
57
0
  tag = d.Lookup(NS_LITERAL_CSTRING("aaaaa"));
58
0
  EXPECT_EQ(tag, Dafsa::kKeyNotFound);
59
0
60
0
  // Empty string.
61
0
  tag = d.Lookup(NS_LITERAL_CSTRING(""));
62
0
  EXPECT_EQ(tag, Dafsa::kKeyNotFound);
63
0
}
64
65
TEST(Dafsa, HugeString)
66
0
{
67
0
  Dafsa d(dafsa_test_1::kDafsa);
68
0
69
0
  int tag = d.Lookup(NS_LITERAL_CSTRING(
70
0
        "This is a very long string that is larger than the dafsa itself. "
71
0
        "This is a very long string that is larger than the dafsa itself. "
72
0
        "This is a very long string that is larger than the dafsa itself. "
73
0
        "This is a very long string that is larger than the dafsa itself. "
74
0
        "This is a very long string that is larger than the dafsa itself. "
75
0
        "This is a very long string that is larger than the dafsa itself. "
76
0
        "This is a very long string that is larger than the dafsa itself. "
77
0
        "This is a very long string that is larger than the dafsa itself. "
78
0
        "This is a very long string that is larger than the dafsa itself. "
79
0
        "This is a very long string that is larger than the dafsa itself. "
80
0
        "This is a very long string that is larger than the dafsa itself. "
81
0
        "This is a very long string that is larger than the dafsa itself. "
82
0
        "This is a very long string that is larger than the dafsa itself. "
83
0
        ));
84
0
  EXPECT_EQ(tag, Dafsa::kKeyNotFound);
85
0
}