-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "StatusTest.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/stat.h> | ||
|
||
#include <SupportKit.h> | ||
|
||
#include "../../GitCommand/Init.h" | ||
|
||
#define PATH "/boot/home/StatusTest" | ||
|
||
CPPUNIT_TEST_SUITE_REGISTRATION(StatusTest); | ||
|
||
void | ||
StatusTest::setUp(void) | ||
{ | ||
// Create a git repo at PATH | ||
Init::InitRepo(PATH); | ||
|
||
char command[1024]; | ||
|
||
// Add initial files | ||
sprintf(command, "touch %s/mod", PATH); | ||
system(command); | ||
sprintf(command, "touch %s/del", PATH); | ||
system(command); | ||
|
||
// Add files to repo | ||
sprintf(command, "(cd %s && git add --all)", PATH); | ||
system(command); | ||
|
||
// Add initial commit | ||
sprintf(command, "(cd %s && git commit -m \"Initial commit\")", PATH); | ||
system(command); | ||
|
||
// Add a file | ||
sprintf(command, "touch %s/nf", PATH); | ||
system(command); | ||
sprintf(command, "(cd %s && git add nf)", PATH); | ||
system(command); | ||
|
||
// Delete a file | ||
sprintf(command, "rm -rf %s/del", PATH); | ||
system(command); | ||
|
||
// Modify a file | ||
sprintf(command, "echo \"Hello World\" > %s/mod", PATH); | ||
system(command); | ||
|
||
// Create new file | ||
sprintf(command, "touch %s/unt", PATH); | ||
system(command); | ||
|
||
// Initialize status object | ||
status = new Status(PATH); | ||
} | ||
|
||
void | ||
StatusTest::tearDown(void) | ||
{ | ||
char command[40]; | ||
|
||
// Remove created repo | ||
sprintf(command, "rm -rf %s", PATH); | ||
system(command); | ||
} | ||
|
||
void | ||
StatusTest::test(void) | ||
{ | ||
BString* statusText = status->GetStatusText(); | ||
|
||
// Check for new file | ||
CPPUNIT_ASSERT (statusText->FindFirst("new file: nf") != B_ERROR); | ||
|
||
// Check for deleted file | ||
CPPUNIT_ASSERT (statusText->FindFirst("deleted: del") != B_ERROR); | ||
|
||
// Check for modified file | ||
CPPUNIT_ASSERT (statusText->FindFirst("modified: mod") != B_ERROR); | ||
|
||
// Check for untracked file | ||
CPPUNIT_ASSERT (statusText->FindFirst("untracked: unt") != B_ERROR); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef _STATUS_TEST_H_ | ||
#define _STATUS_TEST_H_ | ||
|
||
#include <cppunit/TestFixture.h> | ||
#include <cppunit/extensions/HelperMacros.h> | ||
|
||
#include "../../GitCommand/Status.h" | ||
|
||
using namespace std; | ||
|
||
class StatusTest : public CPPUNIT_NS::TestFixture | ||
{ | ||
CPPUNIT_TEST_SUITE(StatusTest); | ||
CPPUNIT_TEST(test); | ||
CPPUNIT_TEST_SUITE_END(); | ||
|
||
public: | ||
void setUp(void); | ||
void tearDown(void); | ||
|
||
protected: | ||
void test(void); | ||
|
||
private: | ||
Status* status; | ||
}; | ||
|
||
#endif |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# file: makefile | ||
# next line has to be changed to the installation-path of CppUnit | ||
CPPUNIT_PATH=/opt/cppunit | ||
|
||
test: StatusTest.o | ||
g++ -o test ../../GitCommand/Init.cpp ../../GitCommand/Status.cpp StatusTest.o test.cpp -L${CPPUNIT_PATH}/lib -lcppunit -lbe -ltracker -lgit2 -g | ||
|
||
clean: | ||
rm -f *.o test |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <cppunit/CompilerOutputter.h> | ||
#include <cppunit/extensions/TestFactoryRegistry.h> | ||
#include <cppunit/TestResult.h> | ||
#include <cppunit/TestResultCollector.h> | ||
#include <cppunit/TestRunner.h> | ||
#include <cppunit/BriefTestProgressListener.h> | ||
|
||
int | ||
main(int argc, char* argv[]) | ||
{ | ||
// informs test-listener about testresults | ||
CPPUNIT_NS :: TestResult testresult; | ||
|
||
// register listener for collecting the test-results | ||
CPPUNIT_NS :: TestResultCollector collectedresults; | ||
testresult.addListener (&collectedresults); | ||
|
||
// register listener for per-test progress output | ||
CPPUNIT_NS :: BriefTestProgressListener progress; | ||
testresult.addListener (&progress); | ||
|
||
// insert test-suite at test-runner by registry | ||
CPPUNIT_NS :: TestRunner testrunner; | ||
testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ()); | ||
testrunner.run (testresult); | ||
|
||
// output results in compiler-format | ||
CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr); | ||
compileroutputter.write (); | ||
|
||
// return 0 if tests were successful | ||
return collectedresults.wasSuccessful () ? 0 : 1; | ||
} |