[Box Backup-dev] COMMIT r507 - box/chris/general/test/win32

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Sat, 25 Feb 2006 19:32:38 +0000 (GMT)


Author: chris
Date: 2006-02-25 19:32:35 +0000 (Sat, 25 Feb 2006)
New Revision: 507

Modified:
   box/chris/general/test/win32/testlibwin32.cpp
Log:
* testlibwin32.cpp
- Added unit tests for getopt


Modified: box/chris/general/test/win32/testlibwin32.cpp
===================================================================
--- box/chris/general/test/win32/testlibwin32.cpp	2006-02-25 19:32:04 UTC (rev 506)
+++ box/chris/general/test/win32/testlibwin32.cpp	2006-02-25 19:32:35 UTC (rev 507)
@@ -6,6 +6,8 @@
 
 #ifdef WIN32
 
+#include <assert.h>
+
 #include "../../bin/bbackupd/BackupDaemon.h"
 #include "BoxPortsAndFiles.h"
 #include "emu.h"
@@ -55,38 +57,60 @@
 	stat("c:\\windows", &ourfs);
 	stat("c:\\autoexec.bat", &ourfs);
 	printf("Finished dir read");
-#if 0
-	//remove - sleepycat include a version of getopt - mine never REALLY worked !
+
 	//test our getopt function
-	std::string commline("-q -c fgfgfg -f -l hello");
+	char * test_argv[] = 
+	{
+		"foobar.exe",
+		"-qwc",
+		"-",
+		"-c",
+		"fgfgfg",
+		"-f",
+		"-l",
+		"hello",
+		"-",
+		"force-sync",
+		NULL
+	};
+	int test_argc;
+	for (test_argc = 0; test_argv[test_argc]; test_argc++) { }
+	const char* opts = "qwc:l:";
 
-	int c;
-	while((c = getopt(commline.size(), (char * const *)commline.c_str(), "qwc:l:")) != -1)
-	{
-		printf("switch = %c, param is %s\r\n", c, optarg);
-	}
-#endif
+	assert(getopt(test_argc, test_argv, opts) == 'q');
+	assert(getopt(test_argc, test_argv, opts) == 'w');
+	assert(getopt(test_argc, test_argv, opts) == 'c');
+	assert(strcmp(optarg, "-") == 0);
+	assert(getopt(test_argc, test_argv, opts) == 'c');
+	assert(strcmp(optarg, "fgfgfg") == 0);
+	assert(getopt(test_argc, test_argv, opts) == '?');
+	assert(optopt == 'f');
+	assert(getopt(test_argc, test_argv, opts) == 'l');
+	assert(strcmp(optarg, "hello") == 0);
+	assert(getopt(test_argc, test_argv, opts) == -1);
+	// assert(optopt == 0); // no more options
+	assert(strcmp(test_argv[optind], "-") == 0);
+	assert(strcmp(test_argv[optind+1], "force-sync") == 0);
 	//end of getopt test
 	
 	//now test our statfs funct
 	stat("c:\\cert.cer", &ourfs);
-	
-	
 
 	char *timee;
 	
 	timee = ctime(&ourfs.st_mtime);
 
-	if ( S_ISREG(ourfs.st_mode))
+	if (S_ISREG(ourfs.st_mode))
 	{
 		printf("is a normal file");
 	}
 	else
 	{
 		printf("is a directory?");
+		exit(1);
 	}
 
-	lstat("c:\\windows", &ourfs);
+	lstat(getenv("WINDIR"), &ourfs);
 
 	if ( S_ISDIR(ourfs.st_mode))
 	{
@@ -95,6 +119,7 @@
 	else
 	{
 		printf("is a file?");
+		exit(1);
 	}
 
 	//test the syslog functions
@@ -108,12 +133,13 @@
 	//first off get the path name for the default 
 	char buf[MAX_PATH];
 	
+	/*
 	GetModuleFileName(NULL, buf, sizeof(buf));
 	std::string buffer(buf);
 	std::string conf("-c " + buffer.substr(0,(buffer.find("win32test.exe"))) + "bbackupd.conf");
 	//std::string conf( "-c " + buffer.substr(0,(buffer.find("bbackupd.exe"))) + "bbackupd.conf");
+	*/
 
-
 	return 0;
 }