]> git.stg.codes - stg.git/commitdiff
Fixed tests.
authorMaxim Mamontov <faust.madf@gmail.com>
Sat, 31 Jan 2015 16:36:56 +0000 (18:36 +0200)
committerMaxim Mamontov <faust.madf@gmail.com>
Sat, 31 Jan 2015 16:36:56 +0000 (18:36 +0200)
include/stg/service_conf.h
include/stg/services.h
tests/test_fee_charge_rules.cpp
tests/test_reconnect_on_tariff_change.cpp
tests/testservices.h [new file with mode: 0644]
tests/testusers.h

index ca58154b2a08d53612b64f6419f4f6e4cdbcfa6b..84f052a557b55f0befe40b09b24cb50547135b82 100644 (file)
@@ -1,10 +1,31 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
 #ifndef SERVICE_CONF_H
 #define SERVICE_CONF_H
 
-#include <string>
-
+#include "resetable.h"
 #include "os_int.h"
 
+#include <string>
+
 struct SERVICE_CONF
 {
 SERVICE_CONF()
@@ -30,6 +51,51 @@ double      cost;
 uint8_t     payDay;
 };
 
+struct SERVICE_CONF_RES
+{
+SERVICE_CONF_RES()
+    : name(), comment(),
+      cost(), payDay()
+{}
+
+SERVICE_CONF_RES(const SERVICE_CONF & rhs)
+    : name(rhs.name), comment(rhs.comment),
+      cost(rhs.cost), payDay(rhs.payDay)
+{}
+
+SERVICE_CONF_RES & operator=(const SERVICE_CONF & conf)
+{
+name = conf.name;
+comment = conf.comment;
+cost = conf.cost;
+payDay = conf.payDay;
+return *this;
+}
+
+SERVICE_CONF GetData() const
+{
+SERVICE_CONF sc;
+sc.name = name.data();
+sc.comment = comment.data();
+sc.cost = cost.data();
+sc.payDay = payDay.data();
+return sc;
+}
+
+void Splice(const SERVICE_CONF_RES & rhs)
+{
+name.splice(rhs.name);
+comment.splice(rhs.comment);
+cost.splice(rhs.cost);
+payDay.splice(rhs.payDay);
+}
+
+RESETABLE<std::string> name;
+RESETABLE<std::string> comment;
+RESETABLE<double>      cost;
+RESETABLE<uint8_t>     payDay;
+};
+
 inline
 bool operator==(const SERVICE_CONF & a, const SERVICE_CONF & b)
 {
index ddec31beb9af61a602a27bb8b8f05ee2956bc34c..140391d0709b86f71e16c0c5a595bae5ff064655 100644 (file)
 #ifndef SERVICES_H
 #define SERVICES_H
 
-#include <string>
-
 #include "service_conf.h"
 
+#include <string>
+
 class ADMIN;
 
 class SERVICES {
@@ -33,7 +33,8 @@ public:
     virtual int Add(const SERVICE_CONF & service, const ADMIN * admin) = 0;
     virtual int Del(const std::string & name, const ADMIN * admin) = 0;
     virtual int Change(const SERVICE_CONF & service, const ADMIN * admin) = 0;
-    virtual bool Find(const std::string & name, SERVICE_CONF * service) = 0;
+    virtual bool Find(const std::string & name, SERVICE_CONF * service) const = 0;
+    virtual bool Find(const std::string & name, SERVICE_CONF_RES * service) const = 0;
     virtual bool Exists(const std::string & name) const = 0;
     virtual const std::string & GetStrError() const = 0;
     virtual size_t Count() const = 0;
index 825c2b3687ef16260d1462dd656a021dcf20b505..2df09be425dd6c530430a06ed9ec458e328129ac 100644 (file)
@@ -7,6 +7,7 @@
 #include "testtariffs.h"
 #include "testadmin.h"
 #include "teststore.h"
+#include "testservices.h"
 
 namespace tut
 {
@@ -40,7 +41,8 @@ namespace tut
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
@@ -72,7 +74,8 @@ namespace tut
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
         USER_PROPERTY<double> & credit(user.GetProperty().credit);
@@ -118,7 +121,8 @@ namespace tut
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
         USER_PROPERTY<double> & credit(user.GetProperty().credit);
index 8e2bb2f986cc4c978fd8b0e5158eb1cf465d9ff5..2bb0438cb6b5cd8fa9ab75f94b56983e2466a379 100644 (file)
@@ -9,6 +9,7 @@
 #include "teststore.h"
 #include "testauth.h"
 #include "testusers.h"
+#include "testservices.h"
 
 class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE<bool>,
                                  private NONCOPYABLE {
@@ -62,7 +63,8 @@ namespace tut
         TEST_STORE store;
         TEST_AUTH auth;
         TEST_USERS users;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, &users);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
 
         AFTER_CONNECTED_NOTIFIER connectionNotifier;
 
@@ -119,7 +121,8 @@ namespace tut
         TEST_STORE store;
         TEST_AUTH auth;
         TEST_USERS users;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, &users);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
 
         AFTER_CONNECTED_NOTIFIER connectionNotifier;
 
diff --git a/tests/testservices.h b/tests/testservices.h
new file mode 100644 (file)
index 0000000..88e2176
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __TEST_SERVICES__
+#define __TEST_SERVICES__
+
+#include "stg/services.h"
+
+class TEST_SERVICES : public SERVICES
+{
+    public:
+        virtual int Add(const SERVICE_CONF & /*service*/, const ADMIN * /*admin*/) { return 0; }
+        virtual int Del(const std::string & /*name*/, const ADMIN * /*admin*/) { return 0; }
+        virtual int Change(const SERVICE_CONF & /*service*/, const ADMIN * /*admin*/) { return 0; }
+        virtual bool Find(const std::string & name, SERVICE_CONF * service) const { return false; }
+        virtual bool Find(const std::string & name, SERVICE_CONF_RES * service) const { return false; }
+        virtual bool Exists(const std::string & name) const { return false; }
+        virtual const std::string & GetStrError() const { return m_errorStr; }
+        virtual size_t Count() const { return 0; }
+
+        virtual int OpenSearch() const { return 0; }
+        virtual int SearchNext(int, SERVICE_CONF * /*service*/) const { return 0; }
+        virtual int CloseSearch(int) const { return 0; }
+
+    private:
+        std::string m_errorStr;
+};
+
+#endif
index 3d3b7931c48f0de70e83382f5ea6a8864e690b62..131fb9b6d06abf65c71efb8c8d41c26ea8447535 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __TEST_USERS_H__
 #define __TEST_USERS_H__
 
+#include "stg/users.h"
+
 class TEST_USERS : public USERS {
     public:
         TEST_USERS() {}