/* * Copyright (C) 2017 Edupals project * * Author: * Enrique Medina Gremaldos * * Source: * https://github.com/edupals/edupals-base-toolkit * * This file is a part of edupals-base-toolkit. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace edupals; using namespace edupals::variant; using namespace std; struct Test { string name; std::function fn; bool passed; Test(string name,std::function fn) { this->name=name; this->fn=fn; this->passed=false; } }; bool test_network() { vector ifaces; ifaces = network::Interface::list(); clog<<"Network interfaces:"< modules = system::modules(); clog<<"* modules:"<"< pids = system::pids(); clog<<"Process id:"< users = system::User::list(); for (system::User& user:users) { clog<<"* "< groups; groups = system::Group::list(); for (system::Group& group:groups) { clog<<"* "< users = group.users(); for (system::User& user:users) { clog<<"* "< queue(8); mutex cm; clog<<"* threading:"<value()<<"]"<value()<<"]"<value()<<"]"<value()<<"]"< data={10,20,30.0,"40"}; vector bytes={0xde,0xad,0xbe,0xef}; Variant g=bytes; Variant h=true; bool ih=h; int32_t ia=a; int64_t id=d; float ib=b; double ie=e; string isf=f; clog<<"implicit conversions:"<5.0f) { status = false; } tmp = parsed/"status"/Type::Boolean; if (tmp.get_boolean()==true) { status = false; } status = true; } catch(...) { status = false; } json::dump(parsed,cout); cout< groups={100,200,201,202,203}; msg["value"]["groups"]=groups; /* msg["A"]=1; msg["B"]=2; msg["value"]=Variant::create_struct(); msg["value"]["name"]="edupals"; vector groups={100,200,201,202,203}; msg["value"]["groups"]=groups; */ ofstream ofile("/tmp/edupals.bson"); bson::dump(msg,ofile); ofile.close(); ifstream ifile("/tmp/edupals.bson"); msg = bson::load(ifile); ifile.close(); json::dump(msg,cout); return true; } bool test_base64() { const string expected_ascii="edupals.base64"; const string expected_b64="ZWR1cGFscy5iYXNlNjQ="; clog<<"references:"< data(expected_ascii.begin(),expected_ascii.end()); string b64; base64::encode(data,b64); clog<<"Encoded:"< test_function) { try { return test_function(); } catch(std::exception& e) { cerr< to_test; map > tests; // system tests tests["system"].push_back(Test("version",test_system_version)); tests["system"].push_back(Test("uptime",test_system_uptime)); tests["system"].push_back(Test("cmdline",test_system_cmdline)); tests["system"].push_back(Test("memory",test_system_memory)); tests["system"].push_back(Test("pids",test_system_pids)); tests["system"].push_back(Test("modules",test_system_modules)); tests["workqueue"].push_back(Test("workqueue",test_threading)); tests["process"].push_back(Test("process",test_process)); tests["network"].push_back(Test("network",test_network)); tests["user"].push_back(Test("user",test_user)); tests["group"].push_back(Test("group",test_group)); //parser tests["parser"].push_back(Test("parser",test_parser)); //variant tests["variant"].push_back(Test("variant",test_variant)); //json tests["json"].push_back(Test("json",test_json)); //bson tests["bson"].push_back(Test("bson",test_bson)); //base64 tests["base64"].push_back(Test("base64",test_base64)); //base64 tests["log"].push_back(Test("log",test_log)); //uri tests["uri"].push_back(Test("uri",test_uri)); cmd::ArgumentParser parser; cmd::ParseResult result; //parser.add_option(cmd::Option('a',"append",cmd::ArgumentType::Required)); //parser.add_option(cmd::Option('n',"level",cmd::ArgumentType::Optional)); parser.add_option(cmd::Option('h',"help",cmd::ArgumentType::None)); parser.add_option(cmd::Option('v',"version",cmd::ArgumentType::None)); result=parser.parse(argc,argv); if (!result.success()) { if (result.unknowns.size()>0) { cout<<"Unknown options: "<0) { clog<<"Missing argument for: "< test_results; for (auto t:to_test) { if (t.second) { clog<<"**********"<