]> git.stg.codes - stg.git/commitdiff
Add new unit test - checking fee charging rules
authorMaxim Mamontov <faust@gts.dp.ua>
Thu, 26 May 2011 12:59:10 +0000 (15:59 +0300)
committerMaxim Mamontov <faust@gts.dp.ua>
Thu, 26 May 2011 12:59:10 +0000 (15:59 +0300)
tests/Makefile
tests/test_fee_charge_rules.cpp [new file with mode: 0644]

index 0635185c09e2dc4155887da33c679ff4a4d6f33c..43643cacffe24e1e21607839074ae14450defe7b 100644 (file)
@@ -1,4 +1,4 @@
-CXXFLAGS+=-g3 -Wall -W -Wextra -DLINUX -I../include -I../projects/stargazer -I../stglibs/stgconffiles.lib -I.
+CXXFLAGS+=-g3 -Wall -W -Wextra -DLINUX -I../include -I../projects/stargazer -I../stglibs/stgconffiles.lib -I. -DUSE_ABSTRACT_SETTINGS
 LIBS=-lpthread
 PROG=tests
 
@@ -7,11 +7,21 @@ SOURCES=main.cpp \
        test_admin_conf.cpp \
        test_tariff.cpp \
        test_conffiles.cpp \
+       test_fee_charge_rules.cpp \
        ../projects/stargazer/tariff_impl.cpp \
+       ../projects/stargazer/user_impl.cpp \
+       ../projects/stargazer/user_property.cpp \
        ../stglibs/conffiles.lib/conffiles.cpp \
-       ../stglibs/common.lib/common.cpp
+       ../stglibs/common.lib/common.cpp \
+       ../stglibs/logger.lib/logger.cpp \
+       ../stglibs/scriptexecuter.lib/scriptexecuter.cpp
 
-all: $(PROG) 
+.PHONY: all includes clean
+
+all: includes $(PROG)
+
+includes:
+       make -C ../stglibs includes
 
 $(PROG): $(subst .cpp,.o,$(SOURCES))
        $(CXX) $(LDFLAGS) $^ $(LIBS) -o $@
diff --git a/tests/test_fee_charge_rules.cpp b/tests/test_fee_charge_rules.cpp
new file mode 100644 (file)
index 0000000..93b7dd6
--- /dev/null
@@ -0,0 +1,63 @@
+#include "tut/tut.hpp"
+
+#include "stg/settings.h"
+#include "stg/user_property.h"
+#include "user_impl.h"
+
+const volatile time_t stgTime = 0;
+
+namespace tut
+{
+    struct fee_charge_rules_data {
+    };
+
+    typedef test_group<fee_charge_rules_data> tg;
+    tg fee_charge_rules_test_group("Fee charge rules tests group");
+
+    typedef tg::object testobject;
+
+    class TEST_SETTINGS : public SETTINGS {
+        public:
+            TEST_SETTINGS(unsigned _feeChargeType)
+                : feeChargeType(_feeChargeType) {}
+
+            const std::string & GetDirName(size_t) const { return dirName; }
+            const std::string & GetScriptsDir() const { return scriptsDir; }
+            unsigned            GetDetailStatWritePeriod() const { return 10; }
+            unsigned            GetStatWritePeriod() const { return 10; }
+            unsigned            GetDayFee() const { return 0; }
+            bool                GetFullFee() const { return false; }
+            unsigned            GetDayResetTraff() const { return 0; }
+            bool                GetSpreadFee() const { return false; }
+            bool                GetFreeMbAllowInet() const { return false; }
+            bool                GetDayFeeIsLastDay() const { return false; }
+            bool                GetWriteFreeMbTraffCost() const { return false; }
+            bool                GetShowFeeInCash() const { return false; }
+            unsigned            GetMessageTimeout() const { return 0; }
+            unsigned            GetFeeChargeType() const { return feeChargeType; }
+            const std::string & GetMonitorDir() const { return monitorDir; }
+            bool                GetMonitoring() const { return false; }
+
+        private:
+            std::string dirName;
+            std::string scriptsDir;
+            std::string monitorDir;
+            unsigned feeChargeType;
+    };
+
+    template<>
+    template<>
+    void testobject::test<1>()
+    {
+        set_test_name("Check classic rules");
+
+        TEST_SETTINGS settings(0);
+        USER_IMPL user(&settings, NULL, NULL, NULL, NULL);
+
+        USER_PROPERTY<double> & cash(user.GetProperty().cash);
+
+        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        cash = 100;
+        ensure_equals("user.cash == 0", user.GetProperty().cash, 100);
+    }
+}