Przeglądaj źródła

refactor: CTest程序不使用using namespace

SongZihuan 3 lat temu
rodzic
commit
d8eef66110

+ 11 - 9
test/src/code-create.cpp

@@ -1,25 +1,27 @@
 #include "aFuncode.h"
-using namespace aFuncode;
-using namespace aFuntool;
 
 int main() {
     {
-        Code start = Code("test.aun");
-        start.getByteCode()->connect(new Code::ByteCode(start, "Test", 1))->connect(
-                new Code::ByteCode(start, Code::ByteCode::block_p, new Code::ByteCode(start, Code::ByteCode::block_p,
-                                                                                      new Code::ByteCode(start, "Test3",
-                                                                                                         2), 2), 2));
+        auto start = aFuncode::Code("test.aun");
+        start.getByteCode()->connect(new aFuncode::Code::ByteCode(start, "Test", 1))->connect(
+                new aFuncode::Code::ByteCode(start,
+                                             aFuncode::Code::ByteCode::block_p,
+                                             new aFuncode::Code::ByteCode(start,
+                                                                          aFuncode::Code::ByteCode::block_p,
+                                                                          new aFuncode::Code::ByteCode(start,
+                                                                                                       "Test3",
+                                                                                                       2), 2), 2));
         start.display();
         std::string md5 = start.getMD5_v1();
         printf("md5: %s\n", md5.c_str());
 
-        getEndian();
+        aFuntool::getEndian();
 
         start.writeByteCode("test.aun");
     }
 
     {
-        Code start = Code("test.aun");
+        aFuncode::Code start = aFuncode::Code("test.aun");
         start.readByteCode("test.aun");
 
         start.display();

+ 3 - 6
test/src/core-down-msg.cpp

@@ -1,11 +1,8 @@
 #include "msg.h"
-using namespace aFuncore;
-using namespace aFuntool;
-
 int main() {
-    auto *um = new DownMessage();
-    um->pushMessage("test-1", new Message());
-    std::cout << um->getMessage<Message>("test-1") << std::endl;
+    auto *um = new aFuncore::DownMessage();
+    um->pushMessage("test-1", new aFuncore::Message());
+    std::cout << um->getMessage<aFuncore::Message>("test-1") << std::endl;
     delete um;
     return 0;
 }

+ 1 - 3
test/src/core-env-var.cpp

@@ -1,9 +1,7 @@
 #include "env-var.h"
-using namespace aFuncore;
-using namespace aFuntool;
 
 int main() {
-    auto *evs = new EnvVarSpace();
+    auto *evs = new aFuncore::EnvVarSpace();
 
     evs->setString("a", "string");
     evs->setNumber("a", 20);

+ 0 - 13
test/src/core-logger.cpp

@@ -1,13 +0,0 @@
-#include "core-logger.h"
-using namespace aFuncore;
-using namespace aFuntool;
-
-int main() {
-    auto factor = aFuntool::LogFactory(std::string(".") + aFuntool::SEP + "aFunlog", true);
-    auto logger = aFuntool::Logger(factor, "aFun");
-    debugLog(&logger, "I am debug\n");
-    infoLog(&logger, "I am info\n");
-    warningLog(&logger, "I am warning\n");
-    errorLog(&logger, "I am error\n");
-    aFunExitReal(EXIT_FAILURE);
-}

+ 9 - 11
test/src/core-up-msg.cpp

@@ -1,16 +1,14 @@
 #include "msg.h"
-using namespace aFuncore;
-using namespace aFuntool;
 
 int main() {
-    auto *um = new UpMessage(nullptr);
-    um->pushMessage("test-1", new Message());
-    std::cout << um->getMessage<Message>("test-1") << std::endl;
+    auto *um = new aFuncore::UpMessage(nullptr);
+    um->pushMessage("test-1", new aFuncore::Message());
+    std::cout << um->getMessage<aFuncore::Message>("test-1") << std::endl;
 
-    auto *um2 = new UpMessage(um);
-    um2->pushMessage("test-2", new Message());
-    std::cout << um2->getMessage<Message>("test-1") << std::endl;
-    std::cout << um2->getMessage<Message>("test-2") << std::endl;
+    auto *um2 = new aFuncore::UpMessage(um);
+    um2->pushMessage("test-2", new aFuncore::Message());
+    std::cout << um2->getMessage<aFuncore::Message>("test-1") << std::endl;
+    std::cout << um2->getMessage<aFuncore::Message>("test-2") << std::endl;
 
     auto msg1 = um2->popMessage("test-2");
     auto msg2 = um2->popMessage("test-1");
@@ -21,8 +19,8 @@ int main() {
     delete msg2;
     delete um2;
 
-    std::cout << um->getMessage<Message>("test-1") << std::endl;
-    std::cout << um->getMessage<Message>("test-2") << std::endl;
+    std::cout << um->getMessage<aFuncore::Message>("test-1") << std::endl;
+    std::cout << um->getMessage<aFuncore::Message>("test-2") << std::endl;
 
     delete um;
     return 0;

+ 2 - 4
test/src/it-init.cpp

@@ -1,6 +1,4 @@
 #include "init.h"
-using namespace aFuncore;
-using namespace aFuntool;
 
 int main() {
     auto factor = aFuntool::LogFactory(std::string(".") + aFuntool::SEP + "aFunlog", true);
@@ -10,8 +8,8 @@ int main() {
     auto info = aFunit::InitInfo(factor, aFun_logger, core_logger, core_logger, sys_logger);
 
     if (!aFunInit(&info)) {
-        printf_stderr(0, "aFunlang init error.");
-        aFunExitReal(EXIT_FAILURE);
+        aFuntool::printf_stderr(0, "aFunlang init error.");
+        aFuntool::aFunExitReal(EXIT_FAILURE);
     }
     return 0;
 }

+ 109 - 114
test/src/run-code.cpp

@@ -1,20 +1,15 @@
 #include "aFunit.h"
 
-using namespace aFunit;
-using namespace aFuncore;
-using namespace aFuncode;
-using namespace aFuntool;
+void progressInterEvent(aFuncore::Inter &inter);
 
-void progressInterEvent(Inter &inter);
-
-class Func1 : public Function {
+class Func1 : public aFuncore::Function {
     class CallFunc1 : public CallFunction {
-        Code &func_code;
-        const Code::ByteCode *call_code;
-        Inter &inter;
+        aFuncode::Code &func_code;
+        const aFuncode::Code::ByteCode *call_code;
+        aFuncore::Inter &inter;
         std::list<ArgCodeList> *acl;
     public:
-        CallFunc1(Code &func_code_, const Code::ByteCode *code_, Inter &inter_) : func_code{func_code_}, call_code{code_}, inter{inter_} {
+        CallFunc1(aFuncode::Code &func_code_, const aFuncode::Code::ByteCode *code_, aFuncore::Inter &inter_) : func_code{func_code_}, call_code{code_}, inter{inter_} {
             (void)call_code;  // 放置 call_code unused
             acl = new std::list<ArgCodeList>;
             if (code_ != nullptr) {
@@ -23,16 +18,16 @@ class Func1 : public Function {
             }
         }
 
-        std::list<ArgCodeList> *getArgCodeList(Inter &, Activation &, const Code::ByteCode *) override {
+        std::list<ArgCodeList> *getArgCodeList(aFuncore::Inter &, aFuncore::Activation &, const aFuncode::Code::ByteCode *) override {
             return acl;
         }
 
         void runFunction() override {
             if (acl->empty())
-                printf_stdout(0, "runFunction No AegCodeList\n");
+                aFuntool::printf_stdout(0, "runFunction No AegCodeList\n");
             else
-                printf_stdout(0, "runFunction : %p\n", acl->begin()->getObject());
-            new ExeActivation(func_code, inter);
+                aFuntool::printf_stdout(0, "runFunction : %p\n", acl->begin()->getObject());
+            new aFuncore::ExeActivation(func_code, inter);
         }
 
         ~CallFunc1() override {
@@ -40,93 +35,93 @@ class Func1 : public Function {
         }
     };
 
-    Code func_code;
+    aFuncode::Code func_code;
 public:
-    explicit Func1(Inter &inter_) : Object("Function", inter_), func_code {"run-code.aun"} {
+    explicit Func1(aFuncore::Inter &inter_) : Object("Function", inter_), func_code {"run-code.aun"} {
         func_code.getByteCode()->connect(
-                new Code::ByteCode(func_code, Code::ByteCode::block_p,
-                                   new Code::ByteCode(func_code, "test-var", 1), 0));
+                new aFuncode::Code::ByteCode(func_code, aFuncode::Code::ByteCode::block_p,
+                                             new aFuncode::Code::ByteCode(func_code, "test-var", 1), 0));
     }
 
     ~Func1() override = default;
 
-    CallFunc1 *getCallFunction(const Code::ByteCode *code, Inter &inter) override {
+    CallFunc1 *getCallFunction(const aFuncode::Code::ByteCode *code, aFuncore::Inter &inter) override {
         return new CallFunc1(func_code, code, inter);
     }
 
     bool isInfix() override {return true;}
 
-    void destruct(Inter &gc_inter) override {
+    void destruct(aFuncore::Inter &gc_inter) override {
         aFuntool::printf_stdout(0, "%p destruct\n", this);
-        auto code = Code("run-code.aun");
-        code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_p,
-                                                       new Code::ByteCode(code, "test-var", 1), 0));
+        auto code = aFuncode::Code("run-code.aun");
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_p,
+                                                                 new aFuncode::Code::ByteCode(code, "test-var", 1), 0));
         gc_inter.runCode(code);
         progressInterEvent(gc_inter);
     };
 };
 
-class Literaler1 : public Literaler {
-    Code func_code;
+class Literaler1 : public aFuncore::Literaler {
+    aFuncode::Code func_code;
 public:
-    explicit Literaler1(Inter &inter_) : Object("Data", inter_), func_code{"run-code.aun"} {
+    explicit Literaler1(aFuncore::Inter &inter_) : Object("Data", inter_), func_code{"run-code.aun"} {
         func_code.getByteCode()->connect(
-                new Code::ByteCode(func_code, Code::ByteCode::block_p,
-                                   new Code::ByteCode(func_code, "test-var", 1), 0));
+                new aFuncode::Code::ByteCode(func_code, aFuncode::Code::ByteCode::block_p,
+                                             new aFuncode::Code::ByteCode(func_code, "test-var", 1), 0));
     }
 
     ~Literaler1() override = default;
 
-    void getObject(const std::string &literal, char prefix, Inter &inter, Activation &) override {
-        aFuntool::cout << "Literaler1: " << literal  << "prefix: " << (prefix == NUL ? '-' : prefix) << "\n";
-        new ExeActivation(func_code, inter);
+    void getObject(const std::string &literal, char prefix, aFuncore::Inter &inter, aFuncore::Activation &) override {
+        aFuntool::cout << "Literaler1: " << literal  << "prefix: " << (prefix == aFuntool::NUL ? '-' : prefix) << "\n";
+        new aFuncore::ExeActivation(func_code, inter);
     }
 };
 
-class CBV1 : public CallBackVar {
-    Code func_code;
+class CBV1 : public aFuncore::CallBackVar {
+    aFuncode::Code func_code;
 public:
-    explicit CBV1(Inter &inter_) : Object("CBV1", inter_), func_code{"run-code.aun"} {
+    explicit CBV1(aFuncore::Inter &inter_) : Object("CBV1", inter_), func_code{"run-code.aun"} {
         func_code.getByteCode()->connect(
-                new Code::ByteCode(func_code, Code::ByteCode::block_p,
-                                   new Code::ByteCode(func_code, "test-var", 1), 0));
+                new aFuncode::Code::ByteCode(func_code, aFuncode::Code::ByteCode::block_p,
+                                             new aFuncode::Code::ByteCode(func_code, "test-var", 1), 0));
     }
 
     ~CBV1() override = default;
 
-    void callBack(Inter &inter, Activation &) override {
+    void callBack(aFuncore::Inter &inter, aFuncore::Activation &) override {
         aFuntool::cout << "CallBackVar callback\n";
-        new ExeActivation(func_code, inter);
+        new aFuncore::ExeActivation(func_code, inter);
     }
 };
 
-class ImportFunction : public Function {
+class ImportFunction : public aFuncore::Function {
     class CallFunc : public CallFunction {
-        const Code::ByteCode *call_code;
-        Inter &inter;
+        const aFuncode::Code::ByteCode *call_code;
+        aFuncore::Inter &inter;
         std::list<ArgCodeList> *acl;
         std::string import;
     public:
-        CallFunc(const Code::ByteCode *code_, Inter &inter_) : call_code{code_}, inter{inter_} {
+        CallFunc(const aFuncode:: Code::ByteCode *code_, aFuncore::Inter &inter_) : call_code{code_}, inter{inter_} {
             if (code_ == nullptr ||
                 code_->getSon() == nullptr ||
                 code_->getSon()->toNext() == nullptr ||
-                code_->getSon()->toNext()->getType() != Code::ByteCode::code_element)
-                throw ArgumentError();
+                code_->getSon()->toNext()->getType() != aFuncode::Code::ByteCode::code_element)
+                throw aFuncore::ArgumentError();
             acl = new std::list<ArgCodeList>;
             import = code_->getSon()->toNext()->getElement();
         }
 
-        std::list<ArgCodeList> *getArgCodeList(Inter &,
-                                               Activation &,
-                                               const Code::ByteCode *) override {
+        std::list<ArgCodeList> *getArgCodeList(aFuncore::Inter &,
+                                               aFuncore::Activation &,
+                                               const aFuncode::Code::ByteCode *) override {
             return acl;
         }
 
         void runFunction() override {
             auto &stream = inter.getActivation()->getDownStream();
             auto none = new Object("None", inter);
-            stream.pushMessage("NORMAL", new NormalMessage(none));
+            stream.pushMessage("NORMAL", new aFuncore::NormalMessage(none));
             none->delReference();
             aFuntool::cout << "Import " << import << " : " << call_code << "\n";
         }
@@ -137,29 +132,29 @@ class ImportFunction : public Function {
     };
 
 public:
-    AFUN_INLINE explicit ImportFunction(Inter &inter_) : Object("Function", inter_) {
+    AFUN_INLINE explicit ImportFunction(aFuncore::Inter &inter_) : Object("Function", inter_) {
 
     }
 
-    AFUN_INLINE explicit ImportFunction(Environment &env_) : Object("Function", env_) {
+    AFUN_INLINE explicit ImportFunction(aFuncore::Environment &env_) : Object("Function", env_) {
 
     }
 
     ~ImportFunction() override = default;
 
-    CallFunc *getCallFunction(const Code::ByteCode *code, Inter &inter) override {
+    CallFunc *getCallFunction(const aFuncode::Code::ByteCode *code, aFuncore::Inter &inter) override {
         return new CallFunc(code, inter);
     }
 };
 
-void printMessage(const std::string &type, Message *msg, Inter &inter) {
+void printMessage(const std::string &type, aFuncore::Message *msg, aFuncore::Inter &inter) {
     if (type == "NORMAL") {
-        auto *msg_ = dynamic_cast<NormalMessage *>(msg);
+        auto *msg_ = dynamic_cast<aFuncore::NormalMessage *>(msg);
         if (msg_ == nullptr)
             return;
         aFuntool::printf_stdout(0, "NORMAL: %p\n", msg_->getObject());
     } else if (type == "ERROR") {
-        auto *msg_ = dynamic_cast<ErrorMessage *>(msg);
+        auto *msg_ = dynamic_cast<aFuncore::ErrorMessage *>(msg);
         if (msg_ == nullptr)
             return;
         int32_t error_std = 0;
@@ -178,7 +173,7 @@ void printMessage(const std::string &type, Message *msg, Inter &inter) {
     }
 }
 
-void progressInterEvent(Inter &inter) {
+void progressInterEvent(aFuncore::Inter &inter) {
     std::string type;
     for (auto msg = inter.getOutMessageStream().popFrontMessage(type); msg != nullptr; msg = inter.getOutMessageStream().popFrontMessage(type)) {
         printMessage(type, msg, inter);
@@ -186,20 +181,20 @@ void progressInterEvent(Inter &inter) {
     }
 }
 
-void thread_test(Inter &son) {
-    auto code = Code("run-code.aun");
-    code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_p,
-                                                   new Code::ByteCode(code, "test-var", 1), 0));
+void thread_test(aFuncore::Inter &son) {
+    auto code = aFuncode::Code("run-code.aun");
+    code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_p,
+                                                             new aFuncode::Code::ByteCode(code, "test-var", 1), 0));
     son.runCode(code);
     progressInterEvent(son);
-    fputs_stdout("\n");
+    aFuntool::fputs_stdout("\n");
 }
 
 int Main() {
-    Environment env{};
-    Inter inter {env};
+    aFuncore::Environment env{};
+    aFuncore::Inter inter {env};
 
-    auto obj = new Object("Object", inter);
+    auto obj = new aFuncore::Object("Object", inter);
     inter.getProtectVarSpace()->defineVar("test-var", obj);
     aFuntool::cout << "obj: " << obj << "\n";
     obj->delReference();
@@ -238,95 +233,95 @@ int Main() {
 
 
     {
-        fputs_stdout("Test-1: block-p & get test-var\n");
-        auto code = Code("run-code.aun");
-        code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_p,
-                                                       new Code::ByteCode(code, "test-var", 1), 0));
+        aFuntool::fputs_stdout("Test-1: block-p & get test-var\n");
+        auto code = aFuncode::Code("run-code.aun");
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_p,
+                                                                 new aFuncode::Code::ByteCode(code, "test-var", 1), 0));
         inter.runCode(code);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     {
-        fputs_stdout("Test-2: block-c & run {test-func test-var}\n");
-        auto code = Code("run-code.aun");
+        aFuntool::fputs_stdout("Test-2: block-c & run {test-func test-var}\n");
+        auto code = aFuncode::Code("run-code.aun");
 
-        auto arg = new Code::ByteCode(code, "test-func", 1);
-        arg->connect(new Code::ByteCode(code, "test-var", 1));
+        auto arg = new aFuncode::Code::ByteCode(code, "test-func", 1);
+        arg->connect(new aFuncode::Code::ByteCode(code, "test-var", 1));
 
-        code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_c, arg, 0));
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_c, arg, 0));
 
         inter.runCode(code);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     {
-        fputs_stdout("Test-3: block-b & run [test-var test-func]\n");
-        auto code = Code("run-code.aun");
+        aFuntool::fputs_stdout("Test-3: block-b & run [test-var test-func]\n");
+        auto code = aFuncode::Code("run-code.aun");
 
-        auto arg = new Code::ByteCode(code, "test-var", 1);
-        arg->connect(new Code::ByteCode(code, "test-func", 1));
+        auto arg = new aFuncode::Code::ByteCode(code, "test-var", 1);
+        arg->connect(new aFuncode::Code::ByteCode(code, "test-func", 1));
 
-        code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_b, arg, 0));
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_b, arg, 0));
         inter.runCode(code);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     {
-        fputs_stdout("Test-4: test-literaler\n");
+        aFuntool::fputs_stdout("Test-4: test-literaler\n");
         inter.pushLiteral("data[0-9]", "test-literaler", false);
-        auto code = Code("run-code.aun");
-        code.getByteCode()->connect(new Code::ByteCode(code, "data4", 1));
+        auto code = aFuncode::Code("run-code.aun");
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, "data4", 1));
         inter.runCode(code);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     {
-        fputs_stdout("Test-5: test-cbv\n");
-        auto code = Code("run-code.aun");
-        code.getByteCode()->connect(new Code::ByteCode(code, "test-cbv", 1));
+        aFuntool::fputs_stdout("Test-5: test-cbv\n");
+        auto code = aFuncode::Code("run-code.aun");
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, "test-cbv", 1));
         inter.runCode(code);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     {
-        fputs_stdout("Test-6: run-function\n");
+        aFuntool::fputs_stdout("Test-6: run-function\n");
         inter.runCode(func);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     {
-        fputs_stdout("Test-7: {import test}\n");
-        auto code = Code("run-code.aun");
+        aFuntool::fputs_stdout("Test-7: {import test}\n");
+        auto code = aFuncode::Code("run-code.aun");
 
-        auto arg = new Code::ByteCode(code, "import", 1);
-        arg->connect(new Code::ByteCode(code, "test", 1));
+        auto arg = new aFuncode::Code::ByteCode(code, "import", 1);
+        arg->connect(new aFuncode::Code::ByteCode(code, "test", 1));
 
-        code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_c, arg, 0));
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_c, arg, 0));
 
         inter.runCode(code);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     {
         /* 多线程 */
-        fputs_stdout("Test-8: thread\n");
-        Inter son{inter};
+        aFuntool::fputs_stdout("Test-8: thread\n");
+        auto son = aFuncore::Inter(inter);
         std::thread thread{thread_test, std::ref(son)};
 
         {
-            auto code = Code("run-code.aun");
-            code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_p,
-                                                           new Code::ByteCode(code, "test-var", 1), 0));
+            auto code = aFuncode::Code("run-code.aun");
+            code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_p,
+                                                                     new aFuncode::Code::ByteCode(code, "test-var", 1), 0));
             inter.runCode(code);
             progressInterEvent(inter);
-            fputs_stdout("\n");
+            aFuntool::fputs_stdout("\n");
         }
 
         thread.join();
@@ -334,20 +329,20 @@ int Main() {
 
     /* 执行错误的代码 */
     {
-        fputs_stdout("Test-a: error not var\n");
-        auto code = Code("run-code.aun");
-        code.getByteCode()->connect(new Code::ByteCode(code, "test-not-var", 1));
+        aFuntool::fputs_stdout("Test-a: error not var\n");
+        auto code = aFuncode::Code("run-code.aun");
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, "test-not-var", 1));
         inter.runCode(code);
         progressInterEvent(inter);
-        fputs_stdout("\n");
+        aFuntool::fputs_stdout("\n");
     }
 
     inter.setInterExit();
 
     {
-        auto code = Code("run-code.aun");
-        code.getByteCode()->connect(new Code::ByteCode(code, Code::ByteCode::block_p,
-                                                       new Code::ByteCode(code, "test-var", 1), 0));
+        auto code = aFuncode::Code("run-code.aun");
+        code.getByteCode()->connect(new aFuncode::Code::ByteCode(code, aFuncode::Code::ByteCode::block_p,
+                                                                 new aFuncode::Code::ByteCode(code, "test-var", 1), 0));
         inter.runCode(code);
         progressInterEvent(inter);
     }
@@ -365,14 +360,14 @@ int main() {
         auto info = aFunit::InitInfo(factor, core_logger, core_logger, sys_logger, it_logger);
 
         if (!aFunInit(&info)) {
-            printf_stderr(0, "aFunlang init error.");
-            aFunExit(EXIT_FAILURE);
+            aFuntool::printf_stderr(0, "aFunlang init error.");
+            aFuntool::aFunExit(EXIT_FAILURE);
         }
 
         exit_code = Main();
-        aFunExit(exit_code);
+        aFuntool::aFunExit(exit_code);
     } catch (aFuntool::Exit &e) {
         exit_code = e.getExitCode();
     }
-    aFunExitReal(exit_code);
+    aFuntool::aFunExitReal(exit_code);
 }

+ 17 - 18
test/src/tool-byte.cpp

@@ -1,6 +1,5 @@
 #include <cstdio>
 #include "aFuntool.h"
-using namespace aFuntool;
 
 
 #define TEST_WRITE(test, type) do{\
@@ -11,8 +10,8 @@ if (!(test)) { \
 
 #define TEST_READ(test, type) do{\
 if (!(test)) { \
-fprintf(stderr, "Test read wrong: " #type "\n"); \
-return EXIT_FAILURE; \
+    fprintf(stderr, "Test read wrong: " #type "\n"); \
+    return EXIT_FAILURE; \
 }}while(0)
 
 int main() {
@@ -22,21 +21,21 @@ int main() {
     int64_t test64 = 40;
     const std::string testStr = "test";
 
-    getEndian();
+    aFuntool::getEndian();
 
-    FILE *file = fileOpen("test.byte", "wb");
+    FILE *file = aFuntool::fileOpen("test.byte", "wb");
     if (file == nullptr) {
         fprintf(stderr, "Can't not creat file: test.byte\n");
         return EXIT_FAILURE;
     }
 
-    TEST_WRITE(byteWriteInt(file, test8), uint8_t);
-    TEST_WRITE(byteWriteInt(file, test16), uint16_t);
-    TEST_WRITE(byteWriteInt(file, test32), uint32_t);
-    TEST_WRITE(byteWriteInt(file, test64), uint64_t);
-    TEST_WRITE(byteWriteStr(file, testStr), str);
+    TEST_WRITE(aFuntool::byteWriteInt(file, test8), uint8_t);
+    TEST_WRITE(aFuntool::byteWriteInt(file, test16), uint16_t);
+    TEST_WRITE(aFuntool::byteWriteInt(file, test32), uint32_t);
+    TEST_WRITE(aFuntool::byteWriteInt(file, test64), uint64_t);
+    TEST_WRITE(aFuntool::byteWriteStr(file, testStr), str);
 
-    fileClose(file);
+    aFuntool::fileClose(file);
 
     int8_t rtest8;
     int16_t rtest16;
@@ -44,17 +43,17 @@ int main() {
     int64_t rtest64;
     std::string rtestStr;
 
-    file = fileOpen("test.byte", "rb");
+    file = aFuntool::fileOpen("test.byte", "rb");
     if (file == nullptr) {
         fprintf(stderr, "Can't not read file: test.byte\n");
         return EXIT_FAILURE;
     }
 
-    TEST_READ(byteReadInt(file, (uint8_t *)&rtest8), uint8_t);
-    TEST_READ(byteReadInt(file, (uint16_t *)&rtest16), uint16_t);
-    TEST_READ(byteReadInt(file, (uint32_t *)&rtest32), uint32_t);
-    TEST_READ(byteReadInt(file, (uint64_t *)&rtest64), uint64_t);
-    TEST_READ(byteReadStr(file, rtestStr), str);
+    TEST_READ(aFuntool::byteReadInt(file, (uint8_t *)&rtest8), uint8_t);
+    TEST_READ(aFuntool::byteReadInt(file, (uint16_t *)&rtest16), uint16_t);
+    TEST_READ(aFuntool::byteReadInt(file, (uint32_t *)&rtest32), uint32_t);
+    TEST_READ(aFuntool::byteReadInt(file, (uint64_t *)&rtest64), uint64_t);
+    TEST_READ(aFuntool::byteReadStr(file, rtestStr), str);
 
     if (rtest8 != test8 || rtest16 != test16 || rtest32 != test32 || rtest64 != test64 || rtestStr != testStr) {
         printf("error.\n");
@@ -66,7 +65,7 @@ int main() {
         return EXIT_FAILURE;
     }
 
-    fileClose(file);
+    aFuntool::fileClose(file);
     printf("success.\n");
     return EXIT_SUCCESS;
 }

+ 5 - 6
test/src/tool-dlc.cpp

@@ -1,20 +1,19 @@
 #include <cstdio>
 #include <cstdlib>
 #include "aFuntool.h"
-using namespace aFuntool;
 
 int test_func() {
     return 100;
 }
 
 int main(int argc, char **argv) {
-    atexit(DlcHandle::dlcExit);
+    atexit(aFuntool::DlcHandle::dlcExit);
 
     if (argc != 2)
         return EXIT_FAILURE;
 
     char *lib = argv[1];
-    DlcHandle dlc {lib, RTLD_NOW};  // TEST_LIB_PATH 传进来的分隔符 都是 "/"
+    aFuntool::DlcHandle dlc {lib, RTLD_NOW};  // TEST_LIB_PATH 传进来的分隔符 都是 "/"
     if (dlc.isOpen()) {
         fprintf(stderr, "libary not found!\n");
         return EXIT_FAILURE;
@@ -23,9 +22,9 @@ int main(int argc, char **argv) {
     typedef int (func)(int a);
     typedef int (test)();
 
-    DlcSymbol<int> a = dlc.getSymbol<int>("num");
-    DlcSymbol<func> fun = dlc.getSymbol<func>("test");
-    DlcSymbol<test> test_fun{test_func, nullptr};
+    auto a = dlc.getSymbol<int>("num");
+    auto fun = dlc.getSymbol<func>("test");
+    auto test_fun = aFuntool::DlcSymbol<test>(test_func, nullptr);
 
     int test_func_result = test_fun.getSymbol()();
 

+ 4 - 5
test/src/tool-exit.cpp

@@ -1,6 +1,5 @@
 #include <iostream>
 #include "aFuntool.h"
-using namespace aFuntool;
 
 void exit_func_push1(void *) {
     std::cout << "I am exit push-1" << std::endl;
@@ -13,11 +12,11 @@ void exit_func_push2(void *) {
 int main() {
     int exit_code = 0;
     try {
-        aFunAtExit(exit_func_push1, nullptr);
-        aFunAtExit(exit_func_push2, nullptr);
-        aFunExit(0);
+        aFuntool::aFunAtExit(exit_func_push1, nullptr);
+        aFuntool::aFunAtExit(exit_func_push2, nullptr);
+        aFuntool::aFunExit(0);
     } catch (aFuntool::Exit &e) {
         exit_code = e.getExitCode();
     }
-    aFunExitReal(exit_code);
+    aFuntool::aFunExitReal(exit_code);
 }

+ 1 - 2
test/src/tool-hash.cpp

@@ -1,7 +1,6 @@
 #include "aFuntool.h"
-using namespace aFuntool;
 
 int main() {
-    std::cout << time33("HelloWorld") << std::endl;
+    std::cout << aFuntool::time33("HelloWorld") << std::endl;
     return 0;
 }

+ 8 - 14
test/src/tool-logger.cpp

@@ -1,17 +1,11 @@
 #include "aFuntool.h"
-using namespace aFuntool;
 
-int main(){
-    int exit_code = 0;
-    try {
-        setlocale(LC_ALL, "");
-
-        auto factor = LogFactory(std::string(".") + SEP + "aFunlog", true);
-        auto logger = Logger(factor, "Test", aFuntool::log_info);
-        infoLog(&logger, "Test logger");
-        aFunExit(0);
-    } catch (aFuntool::Exit &e) {
-        exit_code = e.getExitCode();
-    }
-    aFunExitReal(exit_code);
+int main() {
+    auto factor = aFuntool::LogFactory(std::string(".") + aFuntool::SEP + "aFunlog", true);
+    auto logger = aFuntool::Logger(factor, "aFun");
+    debugLog(&logger, "I am debug\n");
+    infoLog(&logger, "I am info\n");
+    warningLog(&logger, "I am warning\n");
+    errorLog(&logger, "I am error\n");
+    aFuntool::aFunExitReal(EXIT_SUCCESS);
 }

+ 1 - 2
test/src/tool-md5.cpp

@@ -1,5 +1,4 @@
 #include "aFuntool.h"
-using namespace aFuntool;
 
 int main(int argc, char **argv) {
     if (argc != 3)
@@ -7,7 +6,7 @@ int main(int argc, char **argv) {
 
     char *md5_answer = argv[1];
     char *file_path = argv[2];
-    char *my_md5 = getFileMd5(file_path);
+    char *my_md5 = aFuntool::getFileMd5(file_path);
 
     bool ret = !strcmp(my_md5, md5_answer);
     aFuntool::safeFree(my_md5);

+ 2 - 3
test/src/tool-regex.cpp

@@ -1,10 +1,9 @@
 #include <cstdio>
 #include <iostream>
 #include "aFuntool.h"
-using namespace aFuntool;
 
 int main() {
-    Regex rg {"Hello嘿.*d"};
+    aFuntool::Regex rg {"Hello嘿.*d"};
     int rc1 = rg.match("Hello嘿World");
     int rc2 = rg.match("Nossss");
 
@@ -14,7 +13,7 @@ int main() {
     } else
         printf("rg1 success\n");
 
-    Regex rg2 {"你|好"};
+    aFuntool::Regex rg2 {"你|好"};
     int rc3 = rg2.match("你");
     int rc4 = rg2.match("Nosssss");
 

+ 1 - 2
test/src/tool-utf.cpp

@@ -1,6 +1,5 @@
 #include "aFuntool.h"
 #include <clocale>
-using namespace aFuntool;
 
 int main() {
     setlocale(LC_ALL, "");
@@ -10,7 +9,7 @@ int main() {
     const wchar_t *tmp2 = L"你好";
     const char *tmp3 = "你好";
 
-    convertWideByte(&tmp, tmp3, CP_UTF8);
+    aFuntool::convertWideByte(&tmp, tmp3, CP_UTF8);
 
     std::wcout << tmp << std::endl;
     std::wcout << tmp2 << std::endl;