File: WordGenTest.cpp

package info (click to toggle)
dasher 5.0.0~beta~repack2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 70,908 kB
  • sloc: xml: 181,314; cpp: 70,858; java: 8,020; python: 3,579; makefile: 936; sh: 320; ansic: 223; perl: 71
file content (69 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download | duplicates (5)
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
#include "gtest/gtest.h"
#include "../../Src/TestPlatform/MockFileWordGenerator.h"
using namespace Dasher;

/*
 * Test fixture
 */
class WordGenTest : public ::testing::Test {
  public:
    WordGenTest() {
      fullGen = new MockFileWordGenerator("test_data/word_gen_full_data.txt");
      singleLineGen = new MockFileWordGenerator("test_data/word_gen_single_line.txt");
    }
  
  protected:
    MockFileWordGenerator* fullGen;
    MockFileWordGenerator* singleLineGen;
};

/*
 * Tests whether the word fullGenerator opens a file
 * correctly.
 */
TEST_F(WordGenTest, FileOpensCorrectly) {
  bool opened = fullGen->GetFileHandle().is_open();
  bool good = fullGen->GetFileHandle().good();
  ASSERT_EQ(opened, true);
  ASSERT_EQ(good, true);
}

/*
 * Tests whether the file name getter returns expected results.
 */
TEST_F(WordGenTest, FilenameExtraction) {
  ASSERT_EQ("word_gen_full_data.txt", fullGen->GetFilename());
}

/*
 * Tests if retrieving the next word returns expected results.
 */
TEST_F(WordGenTest, WordIteration) {
  ASSERT_EQ("I'm", fullGen->GetNextWord());
  ASSERT_EQ("a", fullGen->GetNextWord());
}

/*
 * Tests if the word generator actually grabs the right amount of data
 * from the stream
 */
TEST_F(WordGenTest, GetBuffer) {
  std::ifstream fin;
  std::string buffer;
  fin.open("test_data/word_gen_single_line.txt");
  std::getline(fin, buffer);
  
  ASSERT_EQ(buffer, singleLineGen->GetWholeBuffer());
}

/* This test /should/ determine whether we return the right value when
 * we reach the end of a file...Not sure what's causing this to fail now
 */
TEST_F(WordGenTest, EndsAtEOF) {
  for(int i = 0; i < 1000; i++)
    singleLineGen->GetNextWord();
    
  ASSERT_EQ("", singleLineGen->GetNextWord());
}