config_test.cpp 776 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <memory>
  2. #include <config_file.h>
  3. #include <log.h>
  4. #define show(x) printf("%s=[%s]\n",k,config.get(k,""));
  5. void test(const char*fname)
  6. {
  7. std::cout<<"----------------------------"<<fname<<"---------------------------\n";
  8. config_file config;
  9. config.open(fname);
  10. config.print(std::cout);
  11. std::cout<<"-------------------------------------------------------\n";
  12. for(auto k:config.keys())
  13. show(k);
  14. log_info("contains(%s)=%d","main.file",config.contains("main.file"));
  15. log_info("contains(%s)=%d","a",config.contains("a"));
  16. config.get("undefined2",0);
  17. config.get("undefined1",nullptr);
  18. std::cout<<"-------------------------------------------------------\n";
  19. config.print(std::cout);
  20. }
  21. int main()
  22. {
  23. test("log.ini");
  24. test("config.ini");
  25. return 0;
  26. }