[go: up one dir, main page]

Menu

[f020ae]: / test.h  Maximize  Restore  History

Download this file

172 lines (137 with data), 5.4 kB

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/////////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: Copyright (C) 2009 Steven Lamerton
// License: GNU GPL 2 (See readme for more info)
/////////////////////////////////////////////////////////////////////////////////
#ifndef H_TEST
#define H_TEST
#include "basicfunctions.h"
#include "path.h"
#include "rules.h"
#include "filecounter.h"
#include <wx/string.h>
#include <wx/datetime.h>
#include <wx/arrstr.h>
#include <wx/stdpaths.h>
#include <wx/textfile.h>
#include <cxxtest/TestSuite.h>
#include <algorithm>
#include <vector>
class VariablesTests : public CxxTest::TestSuite{
public:
void testDate(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("@date@")), wxDateTime::Now().FormatISODate());
}
void testTime(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("@time@")), wxDateTime::Now().Format(wxT("%H")) + wxT("-") + wxDateTime::Now().Format(wxT("%M")));
}
void testYear(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("@YYYY@")), wxDateTime::Now().Format(wxT("%Y")));
}
void testMonth(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("@MM@")), wxDateTime::Now().Format(wxT("%m")));
}
void testDay(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("@DD@")), wxDateTime::Now().Format(wxT("%d")));
}
void testHour(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("@hh@")), wxDateTime::Now().Format(wxT("%H")));
}
void testMinute(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("@mm@")), wxDateTime::Now().Format(wxT("%M")));
}
void testAtEmbedded(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("C:\\thisisa@test\\path.doc")), wxT("C:\\thisisa@test\\path.doc"));
}
void testDateEmbedded(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("C:\\testdir\\@date@.zip")), wxT("C:\\testdir\\") + wxDateTime::Now().FormatISODate() + wxT(".zip"));
}
void testBunchedEmbeddded(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("C:\\@YYYY@@MM@\\@date@.zip")), wxT("C:\\") + wxDateTime::Now().Format(wxT("%Y")) + wxDateTime::Now().Format(wxT("%m")) + wxT("\\") + wxDateTime::Now().FormatISODate()+ wxT(".zip"));
}
void testExtraAt(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("C:\\testdir\\@@date@.zip")), wxT("C:\\testdir\\@") + wxDateTime::Now().FormatISODate() + wxT(".zip"));
TS_ASSERT_EQUALS(Path::Normalise(wxT("C:\\testdir\\@@date@@.zip")), wxT("C:\\testdir\\@") + wxDateTime::Now().FormatISODate() + wxT("@.zip"));
}
void testPlain(){
TS_ASSERT_EQUALS(Path::Normalise(wxT("docs")), wxT("docs"));
}
};
class RulesTests : public CxxTest::TestSuite{
public:
Rules *rules;
wxArrayString fileexclude, folderexclude, locationinclude;
void setUp(){
rules = new Rules("testrules");
//Set up excluded files
fileexclude.Add(wxT(".doc"));
fileexclude.Add(wxT("testex"));
rules->SetExcludedFiles(fileexclude);
//Set up excluded folders
folderexclude.Add(wxT("\\testex"));
rules->SetExcludedFolders(folderexclude);
//Set up included locations
locationinclude.Add("++");
locationinclude.Add("testinc.txt");
rules->SetIncludedLocations(locationinclude);
}
void tearDown(){
delete rules;
}
void testIncludeDefault(){
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\"), true), false); //Included
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\file.txt"), false), false); //Included
}
void testExcludeFile(){
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\test.doc"), false), true); //Excluded
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\testex.txt"), false), true); //Excluded
}
void testExcludeFolder(){
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\Users\\Testexclude\\"), true), true); //Excluded
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\Users\\Testexclude\\test.txt"), false), true); //Excluded
}
void testIncludeLocation(){
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\Users\\Testexclude\\testinc.txt"), false), false); //Included
}
void testCaseInsensative(){
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\Users\\Test\\Documents\\TESTEX.txt"), false), true); //Excluded
}
void testPlusSigns(){
TS_ASSERT_EQUALS(rules->ShouldExclude(wxT("C:\\Users\\Test\\specialchars++.txt"), false), false); //Included
}
};
class FileCounterTests : public CxxTest::TestSuite{
public:
wxString testdir;
std::vector<wxString> folderlist;
void setUp(){
testdir = wxPathOnly(wxStandardPaths::Get().GetExecutablePath()) + wxFILE_SEP_PATH + "unittests" + wxFILE_SEP_PATH;
folderlist.push_back(testdir);
folderlist.push_back(testdir + "subdir1");
folderlist.push_back(testdir + "subdir2");
folderlist.push_back(testdir + "subdir1" + wxFILE_SEP_PATH + "subdir1");
folderlist.push_back(testdir + "subdir1" + wxFILE_SEP_PATH + "subdir2");
std::for_each(folderlist.begin(), folderlist.end(), makedir);
std::for_each(folderlist.begin(), folderlist.end(), createfiles);
}
void tearDown(){
//Flip the list as files must be removed before folders
std::reverse(folderlist.begin(), folderlist.end());
std::for_each(folderlist.begin(), folderlist.end(), deletefiles);
std::for_each(folderlist.begin(), folderlist.end(), deletedir);
}
void testDirectory(){
FileCounter counter;
counter.AddPath(testdir);
counter.Count();
TS_ASSERT_EQUALS(counter.GetCount(), 10);
}
void testFiles(){
FileCounter counter;
counter.AddPath(testdir + "file1");
counter.AddPath(testdir + "subdir1" + wxFILE_SEP_PATH + "file1");
counter.Count();
TS_ASSERT_EQUALS(counter.GetCount(), 2);
}
};
#endif