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());
}
|