瀏覽代碼

Bug fixes, self test of JSONDB disabled by default.

Adam Ierymenko 8 年之前
父節點
當前提交
5f63d5039b
共有 2 個文件被更改,包括 27 次插入2 次删除
  1. 6 0
      controller/JSONDB.hpp
  2. 21 2
      selftest.cpp

+ 6 - 0
controller/JSONDB.hpp

@@ -88,6 +88,9 @@ public:
 		}
 	}
 
+	inline bool operator==(const JSONDB &db) const { return ((_basePath == db._basePath)&&(_db == db._db)); }
+	inline bool operator!=(const JSONDB &db) const { return (!(*this == db)); }
+
 private:
 	void _reload(const std::string &p);
 	bool _isValidObjectName(const std::string &n);
@@ -98,6 +101,9 @@ private:
 		nlohmann::json obj;
 		uint64_t lastModifiedOnDisk;
 		uint64_t lastCheck;
+
+		inline bool operator==(const _E &e) const { return (obj == e.obj); }
+		inline bool operator!=(const _E &e) const { return (obj != e.obj); }
 	};
 
 	std::string _basePath;

+ 21 - 2
selftest.cpp

@@ -809,10 +809,11 @@ static int testOther()
 	}
 	std::cout << "PASS (junk value to prevent optimization-out of test: " << foo << ")" << std::endl;
 
+	/*
 	std::cout << "[other] Testing controller/JSONDB..."; std::cout.flush();
 	{
-		JSONDB db1("jsondb-test");
 		std::map<std::string,nlohmann::json> db1data;
+		JSONDB db1("jsondb-test");
 		for(unsigned int i=0;i<256;++i) {
 			std::string n;
 			for(unsigned int j=0,k=rand() % 4;j<=k;++j) {
@@ -824,8 +825,26 @@ static int testOther()
 			db1data[n] = {{"i",i}};
 			db1.put(n,db1data[n]);
 		}
+		for(std::map<std::string,nlohmann::json>::iterator i(db1data.begin());i!=db1data.end();++i) {
+			i->second["foo"] = "bar";
+			db1.put(i->first,i->second);
+		}
+		JSONDB db2("jsondb-test");
+		if (db1 != db2) {
+			std::cout << " FAILED (db1!=db2 #1)" << std::endl;
+			return -1;
+		}
+		for(std::map<std::string,nlohmann::json>::iterator i(db1data.begin());i!=db1data.end();++i) {
+			db1.erase(i->first);
+		}
+		db2.reload();
+		if (db1 != db2) {
+			std::cout << " FAILED (db1!=db2 #2)" << std::endl;
+			return -1;
+		}
 	}
-	std::cout << "PASS" << std::endl;
+	std::cout << " PASS" << std::endl;
+	*/
 
 	return 0;
 }