::iterator it = g_pWsjcppJsonRpc20HandlerList->begin();
+ for (; it!=g_pWsjcppJsonRpc20HandlerList->end(); ++it) {
+ std::string sCmd = it->first;
+ WsjcppJsonRpc20HandlerBase* pWsjcppJsonRpc20HandlerBase = it->second;
+
+ apimd <<
+ "\n"
+ "" << sCmd << "
\n\n"
+ "## " << sCmd << "\n\n";
+
+ if (pWsjcppJsonRpc20HandlerBase->getDescription() != "") {
+ apimd << pWsjcppJsonRpc20HandlerBase->getDescription() << "\n\n";
+ }
+ apimd <<
+ "Access: unauthorized - **" << (pWsjcppJsonRpc20HandlerBase->haveUnauthorizedAccess() ? "yes" : "no") << "**, "
+ " user - **" << (pWsjcppJsonRpc20HandlerBase->haveUserAccess() ? "yes" : "no") << "**, "
+ " tester - **" << (pWsjcppJsonRpc20HandlerBase->haveTesterAccess() ? "yes" : "no") << "**, "
+ " admin - **" << (pWsjcppJsonRpc20HandlerBase->haveAdminAccess() ? "yes" : "no") << "**\n"
+ "\n";
+
+ apimd << " #### Input params \n\n";
+
+ std::string jsTemplate = "";
+
+ std::vector vVin = pWsjcppJsonRpc20HandlerBase->getParamsDef();
+ for (int i = 0; i < vVin.size(); i++) {
+ WsjcppJsonRpc20ParamDef inDef = vVin[i];
+ std::string nameIn = std::string(inDef.getName());
+
+ apimd << " * " << inDef.getName() << " - " << inDef.getType() << ", " << inDef.getRestrict() << "; " << inDef.getDescription() << "\n";
+
+ if (jsTemplate != "") {
+ jsTemplate += ",\n";
+ }
+ if (inDef.isInteger()) {
+ int nVal = 0;
+ if (inDef.getName() == "onpage") {
+ nVal = 10;
+ }
+ jsTemplate += " \"" + inDef.getName() + "\": " + std::to_string(nVal);
+ } else {
+ jsTemplate += " \"" + inDef.getName() + "\": \"\"";
+ }
+ }
+ apimd <<
+ "\n\n"
+ " #### example call method \n\n"
+ "```\n"
+ "client." + sCmd + "({\n" + jsTemplate + "\n}).done(function(r) {\n"
+ " console.log('Success: ', r);\n"
+ "}).fail(function(err) {\n"
+ " console.error('Error:', err);\n"
+ "});\n"
+ "```"
+ "\n\n"
+ " "
+ "\n\n";
+ }
+
+ apimd.close();
+ std::cout << "\t> OK" << std::endl;
+}
+
+// ---------------------------------------------------------------------
+
+void WsjcppJsonRpc20ExportCliWebJs::exportSampleHtmlFile() {
+ std::string sFilename = this->getExportDir() + "/sample.html";
+ std::ofstream sample_html;
+ std::cout << " * write code to " << sFilename << std::endl;
+ sample_html.open(sFilename);
+ sample_html <<
+ "\r\n"
+ "\r\n"
+ " \r\n"
+ " \r\n"
+ "\r\n"
+ "\r\n"
+ "\r\n"
+ "
Connect to Server
\r\n"
+ "
\r\n"
+ " \r\n"
+ "\r\n"
+ "\r\n"
+ "
Login
\r\n"
+ "
\r\n"
+ "
\r\n"
+ " \r\n"
+ "\r\n"
+ "\r\n"
+ "
Connected
\r\n"
+ " \r\n"
+ "\r\n"
+ "\r\n"
+ "\r\n"
+ "\r\n"
+ "\r\n";
+ sample_html.close();
+ std::cout << "\t> OK" << std::endl;
+}
+
+// ---------------------------------------------------------------------
+
+bool WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebJSFile() {
+
+ std::string sFilename = this->getExportDir() + "/dist/" + this->getPackageName() + ".js";
+ std::ofstream libwjscppcli_web_js_file;
+ std::cout << " * write code to " << sFilename << std::endl;
+ libwjscppcli_web_js_file.open(sFilename);
+
+ // TODO move to fallen
+ std::time_t t = std::time(nullptr);
+ std::stringstream buffer;
+ buffer << std::put_time(std::gmtime(&t), "%d %b %Y");
+ std::string sBuildDate(buffer.str());
+ // now the result is in `buffer.str()`.
+
+ libwjscppcli_web_js_file <<
+ "// This file was automatically generated by " << this->getAppName() << " (" + this->getAppVersion() + "), date: " << sBuildDate << "\r\n"
+ "window." << this->getClassName() << " = window." << this->getClassName() << " || (function() { \r\n"
+ " var self = {};\r\n"
+ " self.appName = '" + this->getAppName() + "';\r\n"
+ " self.appVersion = '" + this->getAppVersion() + "';\r\n"
+ " self.appBuildDate = '" + sBuildDate + "';\r\n"
+ " var _lastm = 0;\r\n"
+ " var _listeners = {};\r\n"
+ " var _connectionState = '?';\r\n"
+ " var _tokenValue = '';\r\n"
+ " var _events = {\r\n";
+
+ for (int i = 0; i < m_vEvents.size(); i++) {
+ libwjscppcli_web_js_file <<
+ " '" << m_vEvents[i] << "': [],\r\n";
+ }
+
+ libwjscppcli_web_js_file <<
+ " };\r\n"
+ " function _lm() { _lastm++; return 'm' + _lastm; };\r\n"
+ " console.warn('" + this->getClassName() + " (" + this->getAppVersion() + ")');\r\n"
+ " self.promise = function() {\r\n"
+ " return {\r\n"
+ " completed: false, failed: false, successed: false, \r\n"
+ " done: function(callback) {\r\n"
+ " this.done_callback = callback;\r\n"
+ " if (this.completed && typeof this.done_callback === 'function' && this.successed) {\r\n"
+ " this.done_callback.apply(this, this.result_arguments);\r\n"
+ " }\r\n"
+ " return this;\r\n"
+ " },\r\n"
+ " fail: function(callback) {\r\n"
+ " this.fail_callback = callback;\r\n"
+ " if (this.completed && typeof this.fail_callback === 'function' && this.failed) {\r\n"
+ " this.fail_callback.apply(this, this.error_arguments);\r\n"
+ " }\r\n"
+ " return this;\r\n"
+ " },\r\n"
+ " resolve: function() {\r\n"
+ " if (!this.completed) {\r\n"
+ " this.result_arguments = arguments; // [];\r\n"
+ " if (typeof this.done_callback === 'function') {\r\n"
+ " this.done_callback.apply(this, this.result_arguments);\r\n"
+ " }\r\n"
+ " }\r\n"
+ " this.successed = true;\r\n"
+ " this.completed = true;\r\n"
+ " },\r\n"
+ " reject: function() {\r\n"
+ " if (!this.completed) {\r\n"
+ " this.error_arguments = arguments;\r\n"
+ " if (typeof this.fail_callback === 'function') {\r\n"
+ " this.fail_callback.apply(this, this.error_arguments);\r\n"
+ " }\r\n"
+ " }\r\n"
+ " this.failed = true;\r\n"
+ " this.completed = true;\r\n"
+ " }\r\n"
+ " }; // end of promise\r\n"
+ " };\r\n"
+ " self.waitAllPromises = function(arr_promise) {\r\n"
+ " var p = self.promise();\r\n"
+ " var max_len = arr_promise.length;\r\n"
+ " var result = [];\r\n"
+ " function cmpl(r) {\r\n"
+ " result.push(r);\r\n"
+ " if (result.length == max_len) {\r\n"
+ " p.resolve(result);\r\n"
+ " }\r\n"
+ " };\r\n"
+ " for (var i in arr_promise) {\r\n"
+ " arr_promise[i].done(cmpl).fail(cmpl);\r\n"
+ " }\r\n"
+ " return p;\r\n"
+ " };\r\n"
+ " self.setToken = function(token) {\r\n"
+ " var date = new Date( new Date().getTime() + (7 * 24 * 60 * 60 * 1000) ); // cookie on week\r\n"
+ " document.cookie = '" + this->getClassName() + "token=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();\r\n"
+ " }\r\n"
+ " self.removeToken = function() {\r\n"
+ " _tokenValue = '';"
+ " document.cookie = '" + this->getClassName() + "token=; path=/;';\r\n"
+ " }\r\n"
+ " self.getToken = function() {\r\n"
+ " var matches = document.cookie.match(new RegExp(\r\n"
+ " '(?:^|; )' + '" + this->getClassName() + "token'.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + '=([^;]*)'\r\n"
+ " ));\r\n"
+ " return matches ? decodeURIComponent(matches[1]) : '';\r\n"
+ " }\r\n"
+ " _tokenValue = self.getToken();\r\n"
+ " self.bind = function(name, f) { _events[name].push(f); }\r\n"
+ " self.unbind = function(name) { _events[name] = []; }\r\n"
+ " function _call(name, data) {\r\n"
+ " function __call(f, data) { setTimeout(function() { f(data) },1)}"
+ " for (var i = 0; i < _events[name].length; i++) {\r\n"
+ " __call(_events[name][i], data);\r\n"
+ " }\r\n"
+ " }\r\n"
+ " self.bind('server', function(response) { \r\n"
+ " console.warn('All: ', response);\r\n"
+ " if (response.app != self.appName) {\r\n"
+ " console.error('AppName: ' + response.app + ', but expected ' + self.appName);\r\n"
+ " }\r\n"
+ " if (response.version != self.appVersion) {\r\n"
+ " console.error('AppVersion: ' + response.version + ', but expected ' + self.appVersion);\r\n"
+ " }\r\n"
+ " }); \r\n"
+ " self.handleCommand = function(response) {\r\n"
+ " var lstn = _listeners[response.m];\r\n"
+ " if (lstn) {\r\n"
+ " setTimeout(function() {\r\n"
+ " if (response['error']) {\r\n"
+ " lstn.reject(response);\r\n"
+ " } else {\r\n"
+ " lstn.resolve(response);\r\n"
+ " }\r\n"
+ " delete _listeners[response.m];\r\n"
+ " },1);\r\n"
+ " } else if (_events[response.cmd]) {\r\n"
+ " _call(response.cmd, response);"
+ " } else {\r\n"
+ " console.error('Not found handler for [' + response.cmd + '/' + response.m + ']');\r\n"
+ " }\r\n"
+ " };\r\n"
+ " self.send = function(obj, def) {\r\n"
+ " obj.m = obj.m || _lm();\r\n"
+ " _listeners[obj.m] = def || self.promise();\r\n"
+ " try {\r\n"
+ " if (self.socket.readyState == 0) {\r\n"
+ " setTimeout(function() {\r\n"
+ " self.send(obj, _listeners[obj.m]);\r\n"
+ " },1000);\r\n"
+ " } else {\r\n"
+ " self.socket.send(JSON.stringify(obj));\r\n"
+ " }\r\n"
+ " } catch(e) {\r\n"
+ " console.error(e);\r\n"
+ " }\r\n"
+ " return _listeners[obj.m];\r\n"
+ " }\r\n"
+ " self.init = function(initParams) {\r\n"
+ " if (!initParams.baseUrl) console.error('Expected baseUrl on initParams');\r\n"
+ " self.socket = new WebSocket(initParams.baseUrl);\r\n"
+ " self.socket.onopen = function() {\r\n"
+ " console.log('WS Opened');\r\n"
+ " _call('connected', {});\r\n"
+ " if (_tokenValue != '') self.token();\r\n"
+ " };\r\n"
+ " self.socket.onclose = function(event) {\r\n"
+ " console.log('Closed');\r\n"
+ " if (event.wasClean) {\r\n"
+ " _call('disconnected', {});\r\n"
+ " } else {\r\n"
+ " _call('broken', {});\r\n"
+ " setTimeout(function() {\r\n"
+ " _call('reconnecting', {});\r\n"
+ " self.init(initParams);\r\n"
+ " }, 10000);\r\n"
+ " // Try reconnect after 5 sec\r\n"
+ " }\r\n"
+ " console.log('Code: ' + event.code + ' Reason: ' + event.reason);\r\n"
+ " };\r\n"
+ " self.socket.onmessage = function(event) {\r\n"
+ " // console.log('Received: ' + event.data);\r\n"
+ " try {\r\n"
+ " var response = JSON.parse(event.data);\r\n"
+ " self.handleCommand(response);\r\n"
+ " } catch(e) {\r\n"
+ " console.error(e);\r\n"
+ " }\r\n"
+ " \r\n"
+ " };\r\n"
+ " self.socket.onerror = function(error) {\r\n"
+ " console.log('Error: ' + error.message);\r\n"
+ " };\r\n"
+ " }\r\n"
+ " self.deinit = function(initParams) {\r\n"
+ " self.removeToken();\r\n"
+ " self.socket.close();\r\n"
+ " }\r\n"
+ " self.userProfile = {bInitUserProfile: false}\r\n"
+ " self.updateUserProfileAsync = function() {\r\n"
+ " setTimeout(function() {\r\n"
+ " self.user().done(function(r) {\r\n"
+ " self.userProfile.bInitUserProfile == true;\r\n"
+ " self.userProfile.university = r.data.university;\r\n"
+ " self.userProfile.country = r.data.country;\r\n"
+ " self.userProfile.city = r.data.city;\r\n"
+ " self.userinfo = {};\r\n"
+ " self.userinfo.id = r.data.id;\r\n"
+ " self.userinfo.nick = r.data.nick;\r\n"
+ " self.userinfo.email = r.data.email;\r\n"
+ " self.userinfo.role = r.data.role;\r\n"
+ " self.userinfo.logo = r.data.logo;\r\n"
+ " _call('userdata', r.data);\r\n"
+ " }).fail(function() {\r\n"
+ " self.removeToken();\r\n"
+ " _call('userdata', {});\r\n"
+ " });\r\n"
+ " },10);\r\n"
+ " }\r\n";
+
+ std::map::iterator it = g_pWsjcppJsonRpc20HandlerList->begin();
+ for (; it!=g_pWsjcppJsonRpc20HandlerList->end(); ++it) {
+ std::string sCmd = it->first;
+ WsjcppJsonRpc20HandlerBase* pWsjcppJsonRpc20HandlerBase = it->second;
+ libwjscppcli_web_js_file <<
+ " self." << sCmd << " = function(params) {\r\n";
+
+ libwjscppcli_web_js_file <<
+ " // Access unauthorized: " << (pWsjcppJsonRpc20HandlerBase->haveUnauthorizedAccess() ? "yes" : "no") << "\r\n"
+ " // Access user: " << (pWsjcppJsonRpc20HandlerBase->haveUserAccess() ? "yes" : "no") << "\r\n"
+ " // Access tester: " << (pWsjcppJsonRpc20HandlerBase->haveTesterAccess() ? "yes" : "no") << "\r\n"
+ " // Access admin: " << (pWsjcppJsonRpc20HandlerBase->haveAdminAccess() ? "yes" : "no") << "\r\n";
+
+ if (pWsjcppJsonRpc20HandlerBase->getActivatedFromVersion() != "") {
+ libwjscppcli_web_js_file <<
+ " // Activated From Version: " << pWsjcppJsonRpc20HandlerBase->getActivatedFromVersion() << "\r\n";
+ }
+
+ if (pWsjcppJsonRpc20HandlerBase->getDeprecatedFromVersion() != "") {
+ libwjscppcli_web_js_file <<
+ " // Deprecated From Version: " + pWsjcppJsonRpc20HandlerBase->getDeprecatedFromVersion() << "\r\n";
+ }
+
+ std::vector vVin = pWsjcppJsonRpc20HandlerBase->getParamsDef();
+ if (vVin.size() > 0) {
+ libwjscppcli_web_js_file <<
+ " // Input params:\r\n";
+ }
+ for (int i = 0; i < vVin.size(); i++) {
+ WsjcppJsonRpc20ParamDef inDef = vVin[i];
+ std::string nameIn = std::string(inDef.getName());
+ libwjscppcli_web_js_file <<
+ " // * " + nameIn + " - " + inDef.getType() + ", " + inDef.getRestrict() + " (" + inDef.getDescription() + ") \r\n";
+ }
+
+ libwjscppcli_web_js_file <<
+ " params = params || {};\r\n"
+ " params.cmd = '" << sCmd << "';\r\n";
+ // check required
+ for (int i = 0; i < vVin.size(); i++) {
+ WsjcppJsonRpc20ParamDef inDef = vVin[i];
+ if (inDef.isRequired()) {
+ std::string nameIn = std::string(vVin[i].getName());
+ libwjscppcli_web_js_file <<
+ " if (params['" + nameIn + "'] == undefined) {\r\n"
+ " console.error('Parameter \"" << nameIn << "\" expected (lib)');\r\n"
+ " }\r\n";
+ }
+ }
+ if (sCmd == "login") {
+ libwjscppcli_web_js_file <<
+ " var ret = self.promise()\r\n"
+ " self.send(params).done(function(r) {\r\n"
+ " _tokenValue = r.token;\r\n"
+ " console.log(_tokenValue);\r\n"
+ " self.userinfo = r.user;\r\n"
+ " self.setToken(_tokenValue);\r\n"
+ " self.updateUserProfileAsync();\r\n"
+ " ret.resolve(r);\r\n"
+ " }).fail(function(err) {\r\n"
+ " self.removeToken();\r\n"
+ " ret.reject(err);\r\n"
+ " })\r\n"
+ " return ret;\r\n";
+ } else if (sCmd == "token") {
+ libwjscppcli_web_js_file <<
+ " if (_tokenValue != '') {\r\n"
+ " var ret = self.promise()\r\n"
+ " params.token = _tokenValue;\r\n"
+ " self.send(params).done(function(r) {\r\n"
+ " self.updateUserProfileAsync();\r\n"
+ " ret.resolve(r);\r\n"
+ " }).fail(function(err) {\r\n"
+ " self.removeToken();\r\n"
+ " _call('userdata', {});\r\n"
+ " ret.reject(err);\r\n"
+ " })\r\n"
+ " return ret;\r\n"
+ " } else {\r\n"
+ " return self.send(params);\r\n"
+ " }\r\n";
+ } else {
+ libwjscppcli_web_js_file
+ << " return self.send(params);\r\n";
+ }
+
+ libwjscppcli_web_js_file
+ << " }\r\n\r\n";
+ }
+
+ libwjscppcli_web_js_file <<
+ " return self;\r\n"
+ "})();\r\n";
+
+ libwjscppcli_web_js_file.close();
+ std::cout << "\t> OK" << std::endl;
+ return true;
+}
+
+// ---------------------------------------------------------------------
+
+void WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebServiceTSFile() {
+ std::string sFilename = this->getExportDir() + "/dist/" + this->getPackageName() + ".service.ts";
+ std::ofstream libwjscppcli_web_service_ts_file;
+ std::cout << " * write code to " << sFilename << std::endl;
+ libwjscppcli_web_service_ts_file.open(sFilename);
+
+ // TODO move to fallen
+ std::time_t t = std::time(nullptr);
+ std::stringstream buffer;
+ buffer << std::put_time(std::gmtime(&t), "%d %b %Y");
+ std::string sBuildDate(buffer.str());
+ // now the result is in `buffer.str()`.
+
+ libwjscppcli_web_service_ts_file <<
+ "// This file was automatically generated by " << this->getAppName() << " (v" + this->getAppVersion() + "), date: " << sBuildDate << "\r\n"
+ "import { Injectable, EventEmitter } from '@angular/core';\r\n"
+ "import { PlatformLocation } from '@angular/common';\r\n"
+ "import { ToastrService } from 'ngx-toastr';\r\n"
+ "\r\n"
+ "declare var FreeHackQuestClientConfig: any;\r\n"
+ "\r\n"
+ "@Injectable({providedIn: 'root'})\r\n"
+ "export class " + this->getClassName() + " {\r\n"
+ " private appName: string = '" + this->getAppName() + "';\r\n"
+ " private appVersion: string = '" + this->getAppVersion() + "';\r\n"
+ " private appBuildDate: string = '" + sBuildDate + "';\r\n"
+ " isAuthorized: boolean = false;\r\n"
+ " connectionState: string = '';\r\n"
+ " serverHost: string = 'localhost';\r\n"
+ " currentProtocol: string = 'http:';\r\n"
+ " private _tokenName: string = '" + this->getClassName() + "_token';\r\n"
+ " userdata: any = {};\r\n"
+ " changedState = new EventEmitter();\r\n"
+ " private _lastm: number = 0;\r\n"
+ " private _listeners: any = {};\r\n"
+ " private _connectionState: string = '?';\r\n"
+ " private _tokenValue: string = '';\r\n"
+ " private _socket: WebSocket = null;\r\n"
+ " private _events: any = {\r\n";
+
+ for (int i = 0; i < m_vEvents.size(); i++) {
+ libwjscppcli_web_service_ts_file <<
+ " '" << m_vEvents[i] << "': [],\r\n";
+ }
+
+ libwjscppcli_web_service_ts_file <<
+ " };\r\n"
+ " private _lastConnectionParams: any = null;\r\n"
+ "\r\n"
+ " constructor(\r\n"
+ " private _location: PlatformLocation,\r\n"
+ " ) {\r\n"
+ " this.serverHost = this._location.hostname;\r\n"
+ " this.currentProtocol = this._location.protocol;\r\n"
+ " console.warn('" + this->getClassName() + " (" + this->getAppVersion() + ")');\r\n"
+ " this._tokenValue = this.getToken();\r\n"
+ " }\r\n"
+ "\r\n"
+ " setToken(token: string) {\r\n"
+ " var date = new Date( new Date().getTime() + (7 * 24 * 60 * 60 * 1000) ); // cookie on week\r\n"
+ " document.cookie = this._tokenName + '=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();\r\n"
+ " }\r\n"
+ " \r\n"
+ " removeToken() {\r\n"
+ " this._tokenValue = '';\r\n"
+ " document.cookie = this._tokenName + '=; path=/;';\r\n"
+ " }\r\n"
+ "\r\n"
+ " getToken() {\r\n"
+ " var matches = document.cookie.match(new RegExp(\r\n"
+ " '(?:^|; )' + this._tokenName.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + '=([^;]*)'\r\n"
+ " ));\r\n"
+ " return matches ? decodeURIComponent(matches[1]) : '';\r\n"
+ " }\r\n"
+ "\r\n"
+ " bind(name: string, f: Function) {\r\n"
+ " this._events[name].push(f);\r\n"
+ " }\r\n"
+ "\r\n"
+ " unbind(name: string) {\r\n"
+ " this._events[name] = [];\r\n"
+ " }\r\n"
+ "\r\n"
+ " _call(name: string, data: any) {\r\n"
+ " function __call(f: any, data: any) {\r\n"
+ " setTimeout(function() { f(data) },1)\r\n"
+ " }\r\n"
+ " for (var i = 0; i < this._events[name].length; i++) {\r\n"
+ " __call(this._events[name][i], data);\r\n"
+ " }\r\n"
+ " }\r\n"
+ "\r\n"
+ " private socketOnOpen() {\r\n"
+ " console.log('FreeHackQuestClient WS Opened');\r\n"
+ " this._call('connected', {});\r\n"
+ " if (this._tokenValue != '') this.token();\r\n"
+ " }\r\n"
+ "\r\n"
+ " private socketOnClose(event: any) {\r\n"
+ " console.log('FreeHackQuestClient Closed');\r\n"
+ " if (event.wasClean) {\r\n"
+ " this._call('disconnected', {});\r\n"
+ " } else {\r\n"
+ " this._call('broken', {});\r\n"
+ " setTimeout(function() {\r\n"
+ " this._call('reconnecting', {});\r\n"
+ " if (this._lastConnectionParams != null) {\r\n"
+ " this.connectToServer(this._lastConnectionParams);\r\n"
+ " }\r\n"
+ " }, 10000);\r\n"
+ " // Try reconnect after 10 sec\r\n"
+ " }\r\n"
+ " console.log('Code: ' + event.code + ' Reason: ' + event.reason);\r\n"
+ " }\r\n"
+ "\r\n"
+ " private _socketOnMessage(event: any) {\r\n"
+ " console.log('FreeHackQuestClient Received: ' + event.data);\r\n"
+ " try {\r\n"
+ " var response = JSON.parse(event.data);\r\n"
+ " // this._handleCommand(response);\r\n"
+ " } catch(e) {\r\n"
+ " console.error(e);\r\n"
+ " }\r\n"
+ " }\r\n"
+ "\r\n"
+ " private _socketOnError(error: any) {\r\n"
+ " console.log('FreeHackQuestClient Socket Error: ', error);\r\n"
+ " }\r\n"
+ "\r\n"
+ " connectToServer(initParams: any) {\r\n"
+ " this._lastConnectionParams = null;\r\n"
+ " if (!initParams.baseUrl) console.error('Expected baseUrl on initParams');\r\n"
+ " this._lastConnectionParams = initParams;\r\n"
+ " this._socket = new WebSocket(initParams.baseUrl);\r\n"
+ " this._socket.onopen = (() => this.socketOnOpen());\r\n"
+ " this._socket.onclose = ((event: any) => this.socketOnClose(event));\r\n"
+ " this._socket.onmessage = ((event: any) => this._socketOnMessage(event));\r\n"
+ " this._socket.onerror = ((error: any) => this._socketOnError(error));\r\n"
+ " }\r\n"
+ "\r\n"
+ " private _lm() { this._lastm++; return 'm' + this._lastm; };\r\n"
+ "\r\n";
+
+
+ libwjscppcli_web_service_ts_file <<
+ " };\r\n"
+ " function _lm() { _lastm++; return 'm' + _lastm; };\r\n"
+ " self.promise = function() {\r\n"
+ " return {\r\n"
+ " completed: false, failed: false, successed: false, \r\n"
+ " done: function(callback) {\r\n"
+ " this.done_callback = callback;\r\n"
+ " if (this.completed && typeof this.done_callback === 'function' && this.successed) {\r\n"
+ " this.done_callback.apply(this, this.result_arguments);\r\n"
+ " }\r\n"
+ " return this;\r\n"
+ " },\r\n"
+ " fail: function(callback) {\r\n"
+ " this.fail_callback = callback;\r\n"
+ " if (this.completed && typeof this.fail_callback === 'function' && this.failed) {\r\n"
+ " this.fail_callback.apply(this, this.error_arguments);\r\n"
+ " }\r\n"
+ " return this;\r\n"
+ " },\r\n"
+ " resolve: function() {\r\n"
+ " if (!this.completed) {\r\n"
+ " this.result_arguments = arguments; // [];\r\n"
+ " if (typeof this.done_callback === 'function') {\r\n"
+ " this.done_callback.apply(this, this.result_arguments);\r\n"
+ " }\r\n"
+ " }\r\n"
+ " this.successed = true;\r\n"
+ " this.completed = true;\r\n"
+ " },\r\n"
+ " reject: function() {\r\n"
+ " if (!this.completed) {\r\n"
+ " this.error_arguments = arguments;\r\n"
+ " if (typeof this.fail_callback === 'function') {\r\n"
+ " this.fail_callback.apply(this, this.error_arguments);\r\n"
+ " }\r\n"
+ " }\r\n"
+ " this.failed = true;\r\n"
+ " this.completed = true;\r\n"
+ " }\r\n"
+ " }; // end of promise\r\n"
+ " };\r\n"
+ " self.waitAllPromises = function(arr_promise) {\r\n"
+ " var p = self.promise();\r\n"
+ " var max_len = arr_promise.length;\r\n"
+ " var result = [];\r\n"
+ " function cmpl(r) {\r\n"
+ " result.push(r);\r\n"
+ " if (result.length == max_len) {\r\n"
+ " p.resolve(result);\r\n"
+ " }\r\n"
+ " };\r\n"
+ " for (var i in arr_promise) {\r\n"
+ " arr_promise[i].done(cmpl).fail(cmpl);\r\n"
+ " }\r\n"
+ " return p;\r\n"
+ " };\r\n"
+ " self.setToken = function(token) {\r\n"
+ " var date = new Date( new Date().getTime() + (7 * 24 * 60 * 60 * 1000) ); // cookie on week\r\n"
+ " document.cookie = '" + this->getClassName() + "token=' + encodeURIComponent(token) + '; path=/; expires='+date.toUTCString();\r\n"
+ " }\r\n"
+ " self.removeToken = function() {\r\n"
+ " _tokenValue = '';"
+ " document.cookie = '" + this->getClassName() + "token=; path=/;';\r\n"
+ " }\r\n"
+ " self.getToken = function() {\r\n"
+ " var matches = document.cookie.match(new RegExp(\r\n"
+ " '(?:^|; )' + '" + this->getClassName() + "token'.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + '=([^;]*)'\r\n"
+ " ));\r\n"
+ " return matches ? decodeURIComponent(matches[1]) : '';\r\n"
+ " }\r\n"
+ " _tokenValue = self.getToken();\r\n"
+ " self.bind = function(name, f) { _events[name].push(f); }\r\n"
+ " self.unbind = function(name) { _events[name] = []; }\r\n"
+ " function _call(name, data) {\r\n"
+ " function __call(f, data) { setTimeout(function() { f(data) },1)}"
+ " for (var i = 0; i < _events[name].length; i++) {\r\n"
+ " __call(_events[name][i], data);\r\n"
+ " }\r\n"
+ " }\r\n"
+ " self.bind('server', function(response) { \r\n"
+ " console.warn('All: ', response);\r\n"
+ " if (response.app != self.appName) {\r\n"
+ " console.error('AppName: ' + response.app + ', but expected ' + self.appName);\r\n"
+ " }\r\n"
+ " if (response.version != self.appVersion) {\r\n"
+ " console.error('AppVersion: ' + response.version + ', but expected ' + self.appVersion);\r\n"
+ " }\r\n"
+ " }); \r\n"
+ " self.handleCommand = function(response) {\r\n"
+ " var lstn = _listeners[response.m];\r\n"
+ " if (lstn) {\r\n"
+ " setTimeout(function() {\r\n"
+ " if (response['error']) {\r\n"
+ " lstn.reject(response);\r\n"
+ " } else {\r\n"
+ " lstn.resolve(response);\r\n"
+ " }\r\n"
+ " delete _listeners[response.m];\r\n"
+ " },1);\r\n"
+ " } else if (_events[response.cmd]) {\r\n"
+ " _call(response.cmd, response);"
+ " } else {\r\n"
+ " console.error('Not found handler for [' + response.cmd + '/' + response.m + ']');\r\n"
+ " }\r\n"
+ " };\r\n"
+ " self.send = function(obj, def) {\r\n"
+ " obj.m = obj.m || _lm();\r\n"
+ " _listeners[obj.m] = def || self.promise();\r\n"
+ " try {\r\n"
+ " if (self.socket.readyState == 0) {\r\n"
+ " setTimeout(function() {\r\n"
+ " self.send(obj, _listeners[obj.m]);\r\n"
+ " },1000);\r\n"
+ " } else {\r\n"
+ " self.socket.send(JSON.stringify(obj));\r\n"
+ " }\r\n"
+ " } catch(e) {\r\n"
+ " console.error(e);\r\n"
+ " }\r\n"
+ " return _listeners[obj.m];\r\n"
+ " }\r\n"
+ " self.init = function(initParams) {\r\n"
+ " if (!initParams.baseUrl) console.error('Expected baseUrl on initParams');\r\n"
+ " self.socket = new WebSocket(initParams.baseUrl);\r\n"
+ " self.socket.onopen = function() {\r\n"
+ " console.log('WS Opened');\r\n"
+ " _call('connected', {});\r\n"
+ " if (_tokenValue != '') self.token();\r\n"
+ " };\r\n"
+ " self.socket.onclose = function(event) {\r\n"
+ " console.log('Closed');\r\n"
+ " if (event.wasClean) {\r\n"
+ " _call('disconnected', {});\r\n"
+ " } else {\r\n"
+ " _call('broken', {});\r\n"
+ " setTimeout(function() {\r\n"
+ " _call('reconnecting', {});\r\n"
+ " self.init(initParams);\r\n"
+ " }, 10000);\r\n"
+ " // Try reconnect after 5 sec\r\n"
+ " }\r\n"
+ " console.log('Code: ' + event.code + ' Reason: ' + event.reason);\r\n"
+ " };\r\n"
+ " self.socket.onmessage = function(event) {\r\n"
+ " // console.log('Received: ' + event.data);\r\n"
+ " try {\r\n"
+ " var response = JSON.parse(event.data);\r\n"
+ " self.handleCommand(response);\r\n"
+ " } catch(e) {\r\n"
+ " console.error(e);\r\n"
+ " }\r\n"
+ " \r\n"
+ " };\r\n"
+ " self.socket.onerror = function(error) {\r\n"
+ " console.log('Error: ' + error.message);\r\n"
+ " };\r\n"
+ " }\r\n"
+ " self.deinit = function(initParams) {\r\n"
+ " self.removeToken();\r\n"
+ " self.socket.close();\r\n"
+ " }\r\n"
+ " self.userProfile = {bInitUserProfile: false}\r\n"
+ " self.updateUserProfileAsync = function() {\r\n"
+ " setTimeout(function() {\r\n"
+ " self.user().done(function(r) {\r\n"
+ " self.userProfile.bInitUserProfile == true;\r\n"
+ " self.userProfile.university = r.data.university;\r\n"
+ " self.userProfile.country = r.data.country;\r\n"
+ " self.userProfile.city = r.data.city;\r\n"
+ " self.userinfo = {};\r\n"
+ " self.userinfo.id = r.data.id;\r\n"
+ " self.userinfo.nick = r.data.nick;\r\n"
+ " self.userinfo.email = r.data.email;\r\n"
+ " self.userinfo.role = r.data.role;\r\n"
+ " self.userinfo.logo = r.data.logo;\r\n"
+ " _call('userdata', r.data);\r\n"
+ " }).fail(function() {\r\n"
+ " self.removeToken();\r\n"
+ " _call('userdata', {});\r\n"
+ " });\r\n"
+ " },10);\r\n"
+ " }\r\n";
+
+ std::map::iterator it = g_pWsjcppJsonRpc20HandlerList->begin();
+ for (; it!=g_pWsjcppJsonRpc20HandlerList->end(); ++it) {
+ std::string sCmd = it->first;
+ WsjcppJsonRpc20HandlerBase* pWsjcppJsonRpc20HandlerBase = it->second;
+ libwjscppcli_web_service_ts_file <<
+ " self." << sCmd << " = function(params) {\r\n";
+
+ libwjscppcli_web_service_ts_file <<
+ " // Access unauthorized: " << (pWsjcppJsonRpc20HandlerBase->haveUnauthorizedAccess() ? "yes" : "no") << "\r\n"
+ " // Access user: " << (pWsjcppJsonRpc20HandlerBase->haveUserAccess() ? "yes" : "no") << "\r\n"
+ " // Access tester: " << (pWsjcppJsonRpc20HandlerBase->haveTesterAccess() ? "yes" : "no") << "\r\n"
+ " // Access admin: " << (pWsjcppJsonRpc20HandlerBase->haveAdminAccess() ? "yes" : "no") << "\r\n";
+
+ if (pWsjcppJsonRpc20HandlerBase->getActivatedFromVersion() != "") {
+ libwjscppcli_web_service_ts_file <<
+ " // Activated From Version: " << pWsjcppJsonRpc20HandlerBase->getActivatedFromVersion() << "\r\n";
+ }
+
+ if (pWsjcppJsonRpc20HandlerBase->getDeprecatedFromVersion() != "") {
+ libwjscppcli_web_service_ts_file <<
+ " // Deprecated From Version: " + pWsjcppJsonRpc20HandlerBase->getDeprecatedFromVersion() << "\r\n";
+ }
+
+ std::vector vVin = pWsjcppJsonRpc20HandlerBase->getParamsDef();
+ if (vVin.size() > 0) {
+ libwjscppcli_web_service_ts_file <<
+ " // Input params:\r\n";
+ }
+ for (int i = 0; i < vVin.size(); i++) {
+ WsjcppJsonRpc20ParamDef inDef = vVin[i];
+ std::string nameIn = std::string(inDef.getName());
+ libwjscppcli_web_service_ts_file <<
+ " // * " + nameIn + " - " + inDef.getType() + ", " + inDef.getRestrict() + " (" + inDef.getDescription() + ") \r\n";
+ }
+
+ libwjscppcli_web_service_ts_file <<
+ " params = params || {};\r\n"
+ " params.cmd = '" << sCmd << "';\r\n";
+ // check required
+ for (int i = 0; i < vVin.size(); i++) {
+ WsjcppJsonRpc20ParamDef inDef = vVin[i];
+ if (inDef.isRequired()) {
+ std::string nameIn = std::string(vVin[i].getName());
+ libwjscppcli_web_service_ts_file <<
+ " if (params['" + nameIn + "'] == undefined) {\r\n"
+ " console.error('Parameter \"" << nameIn << "\" expected (lib)');\r\n"
+ " }\r\n";
+ }
+ }
+ if (sCmd == "login") {
+ libwjscppcli_web_service_ts_file <<
+ " var ret = self.promise()\r\n"
+ " self.send(params).done(function(r) {\r\n"
+ " _tokenValue = r.token;\r\n"
+ " console.log(_tokenValue);\r\n"
+ " self.userinfo = r.user;\r\n"
+ " self.setToken(_tokenValue);\r\n"
+ " self.updateUserProfileAsync();\r\n"
+ " ret.resolve(r);\r\n"
+ " }).fail(function(err) {\r\n"
+ " self.removeToken();\r\n"
+ " ret.reject(err);\r\n"
+ " })\r\n"
+ " return ret;\r\n";
+ } else if (sCmd == "token") {
+ libwjscppcli_web_service_ts_file <<
+ " if (_tokenValue != '') {\r\n"
+ " var ret = self.promise()\r\n"
+ " params.token = _tokenValue;\r\n"
+ " self.send(params).done(function(r) {\r\n"
+ " self.updateUserProfileAsync();\r\n"
+ " ret.resolve(r);\r\n"
+ " }).fail(function(err) {\r\n"
+ " self.removeToken();\r\n"
+ " _call('userdata', {});\r\n"
+ " ret.reject(err);\r\n"
+ " })\r\n"
+ " return ret;\r\n"
+ " } else {\r\n"
+ " return self.send(params);\r\n"
+ " }\r\n";
+ } else {
+ libwjscppcli_web_service_ts_file
+ << " return self.send(params);\r\n";
+ }
+
+ libwjscppcli_web_service_ts_file
+ << " }\r\n\r\n";
+ }
+
+ libwjscppcli_web_service_ts_file <<
+ " return self;\r\n"
+ "})();\r\n";
+
+ libwjscppcli_web_service_ts_file.close();
+ std::cout << "\t> OK" << std::endl;
+}
\ No newline at end of file
diff --git a/src/wsjcpp_jsonrpc20_export_cli_webjs.h b/src/wsjcpp_jsonrpc20_export_cli_webjs.h
new file mode 100644
index 0000000..480e837
--- /dev/null
+++ b/src/wsjcpp_jsonrpc20_export_cli_webjs.h
@@ -0,0 +1,48 @@
+#ifndef WSJCPP_JSONRPC20_EXPORT_CLI_WEBJS_H
+#define WSJCPP_JSONRPC20_EXPORT_CLI_WEBJS_H
+
+#include "wsjcpp_jsonrpc20_export_cli_base.h"
+#include
+
+class WsjcppJsonRpc20ExportCliWebJs : public WsjcppJsonRpc20ExportCliBase {
+ public:
+ WsjcppJsonRpc20ExportCliWebJs(
+ const std::string &sExportDir,
+ const std::string &sPackageName
+ );
+ // TODO homepage
+ void setIssuesURL(const std::string &sIssuesURL);
+ void setRepository(const std::string &sRepositoryType, const std::string &sRepositoryURL);
+ void setKeywords(const std::vector &vKeywords);
+ void setLicense(const std::string &sLicenseType, const std::string &sLicenseURL);
+ void setDefaultConnectionString(const std::string &sDefaultConnectionString);
+ virtual bool doExportLib() override;
+
+ private:
+ std::string TAG;
+ std::string m_sIssuesURL;
+ std::string m_sRepositoryType;
+ std::string m_sRepositoryURL;
+ std::vector m_vKeywords;
+ std::string m_sLicenseType;
+ std::string m_sLicenseURL;
+ std::string m_sDefaultConnectionString;
+
+ std::string m_sSampleUrlConnection;
+
+ std::vector> m_vMethodsForKeepAuthToken;
+ std::vector m_vMethodsForClearAuthToken;
+
+ std::vector m_vEvents;
+
+ bool prepareDirs();
+ bool exportLibCliWebJSFile();
+
+ void exportPackageJson();
+ void exportAPImd();
+
+ void exportLibCliWebServiceTSFile();
+ void exportSampleHtmlFile();
+};
+
+#endif // WSJCPP_JSONRPC20_EXPORT_CLI_WEBJS_H
\ No newline at end of file
diff --git a/unit-tests.wsjcpp/CMakeLists.txt b/unit-tests.wsjcpp/CMakeLists.txt
index f220a38..3713a94 100644
--- a/unit-tests.wsjcpp/CMakeLists.txt
+++ b/unit-tests.wsjcpp/CMakeLists.txt
@@ -1,8 +1,8 @@
-# Automaticly generated by wsjcpp@v0.1.7
+# Automaticly generated by wsjcpp@v0.2.0
cmake_minimum_required(VERSION 3.0)
project(unit-tests C CXX)
-add_definitions(-DWSJCPP_APP_VERSION="ut-v0.0.3")
+add_definitions(-DWSJCPP_APP_VERSION="ut-v0.0.4")
add_definitions(-DWSJCPP_APP_NAME="unit-tests-wsjcpp-jsonrpc20")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -19,15 +19,13 @@ set (WSJCPP_SOURCES "")
find_package(Threads REQUIRED)
list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
-# wsjcpp-core:v0.2.0
+# wsjcpp-core:v0.2.1
list (APPEND WSJCPP_INCLUDE_DIRS "../src.wsjcpp/wsjcpp_core/")
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp")
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_core.h")
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp")
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h")
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp")
-list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.h")
-list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.cpp")
# nlohmann/json:v3.9.1
list (APPEND WSJCPP_INCLUDE_DIRS "../src.wsjcpp/nlohmann_json/")
@@ -38,24 +36,23 @@ list (APPEND WSJCPP_INCLUDE_DIRS "../src.wsjcpp/wsjcpp_validators/")
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_validators/wsjcpp_validators.h")
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_validators/wsjcpp_validators.cpp")
-# wsjcpp-jsonrpc20:v0.0.3
+# wsjcpp-jsonrpc20:v0.0.4
list (APPEND WSJCPP_INCLUDE_DIRS "../src")
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20.h")
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20.cpp")
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20_export_cli_python.h")
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20_export_cli_python.cpp")
+list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20_export_cli_webjs.h")
+list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20_export_cli_webjs.cpp")
+list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20_export_cli_base.h")
+list (APPEND WSJCPP_SOURCES "../src/wsjcpp_jsonrpc20_export_cli_base.cpp")
# unit-tests
list (APPEND WSJCPP_INCLUDE_DIRS "src")
-list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.h")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.cpp")
-list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.h")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.cpp")
-list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_request_server_api.h")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_request_server_api.cpp")
-list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_parsing_request_params.h")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_parsing_request_params.cpp")
-list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_request_parse_income_data.h")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_request_parse_income_data.cpp")
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.user-custom.txt)
@@ -67,11 +64,3 @@ add_executable ("unit-tests" ${WSJCPP_SOURCES})
target_link_libraries("unit-tests" -lpthread ${WSJCPP_LIBRARIES} )
-install(
- TARGETS
- "unit-tests"
- RUNTIME DESTINATION
- /usr/bin
-)
-
-
diff --git a/unit-tests.wsjcpp/build_simple.sh b/unit-tests.wsjcpp/build_simple.sh
index 5c3dfd7..8b35d10 100755
--- a/unit-tests.wsjcpp/build_simple.sh
+++ b/unit-tests.wsjcpp/build_simple.sh
@@ -1,7 +1,7 @@
#!/bin/bash
if [ ! -d tmp ]; then
- mkdir -p tmp
+ mkdir -p tmp
fi
cd tmp
diff --git a/unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.cpp b/unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.cpp
index 7442d2f..0f5cb47 100644
--- a/unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.cpp
+++ b/unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.cpp
@@ -33,55 +33,55 @@ void UnitTestJsonRpc20ParamDef::executeTest() {
{
WsjcppJsonRpc20ParamDef paramDef;
- compareS("Empty paramDef - name", paramDef.getName(), "");
- compareS("Empty paramDef - getType", paramDef.getType(), "");
- compareS("Empty paramDef - getRestrict", paramDef.getRestrict(), "");
- compareS("Empty paramDef - getDescription", paramDef.getDescription(), "");
- compareB("Empty paramDef - isRequired", paramDef.isRequired(), false);
- compareB("Empty paramDef - isOptional", paramDef.isOptional(), false);
- compareB("Empty paramDef - isInteger", paramDef.isInteger(), false);
- compareB("Empty paramDef - isString", paramDef.isString(), false);
- compareB("Empty paramDef - isBool", paramDef.isBool(), false);
- compareB("Empty paramDef - isJson", paramDef.isJson(), false);
+ compare("Empty paramDef - name", paramDef.getName(), "");
+ compare("Empty paramDef - getType", paramDef.getType(), "");
+ compare("Empty paramDef - getRestrict", paramDef.getRestrict(), "required"); // default
+ compare("Empty paramDef - getDescription", paramDef.getDescription(), "");
+ compare("Empty paramDef - isRequired", paramDef.isRequired(), true);
+ compare("Empty paramDef - isOptional", paramDef.isOptional(), false);
+ compare("Empty paramDef - isInteger", paramDef.isInteger(), false);
+ compare("Empty paramDef - isString", paramDef.isString(), false);
+ compare("Empty paramDef - isBool", paramDef.isBool(), false);
+ compare("Empty paramDef - isJson", paramDef.isJson(), false);
nlohmann::json js_empty;
js_empty["description"] = "";
js_empty["name"] = "";
- js_empty["restrict"] = "";
+ js_empty["restrict"] = "required";
js_empty["type"] = "";
- compareS("Empty paramDef - toJson", paramDef.toJson().dump(), js_empty.dump());
+ compare("Empty paramDef - toJson", paramDef.toJson().dump(), js_empty.dump());
- compareN("Empty paramDef - listOfStringValidators", paramDef.listOfStringValidators().size(), 0);
- compareN("Empty paramDef - listOfIntegerValidators", paramDef.listOfIntegerValidators().size(), 0);
- compareN("Empty paramDef - listOfJsonValidators", paramDef.listOfJsonValidators().size(), 0);
+ compare("Empty paramDef - listOfStringValidators", paramDef.listOfStringValidators().size(), 0);
+ compare("Empty paramDef - listOfIntegerValidators", paramDef.listOfIntegerValidators().size(), 0);
+ compare("Empty paramDef - listOfJsonValidators", paramDef.listOfJsonValidators().size(), 0);
}
{
WsjcppJsonRpc20ParamDef paramDef2("arg2", "Some argument222222");
paramDef2.string_().required()
.addValidator(new WsjcppValidatorURL());
- compareS("paramDef2 - name", paramDef2.getName(), "arg2");
- compareS("paramDef2 - getType", paramDef2.getType(), "string");
- compareS("paramDef2 - getRestrict", paramDef2.getRestrict(), "required");
- compareS("paramDef2 - getDescription", paramDef2.getDescription(), "Some argument222222");
- compareB("paramDef2 - isRequired", paramDef2.isRequired(), true);
- compareB("paramDef2 - isOptional", paramDef2.isOptional(), false);
- compareB("paramDef2 - isInteger", paramDef2.isInteger(), false);
- compareB("paramDef2 - isString", paramDef2.isString(), true);
+ compare("paramDef2 - name", paramDef2.getName(), "arg2");
+ compare("paramDef2 - getType", paramDef2.getType(), "string");
+ compare("paramDef2 - getRestrict", paramDef2.getRestrict(), "required");
+ compare("paramDef2 - getDescription", paramDef2.getDescription(), "Some argument222222");
+ compare("paramDef2 - isRequired", paramDef2.isRequired(), true);
+ compare("paramDef2 - isOptional", paramDef2.isOptional(), false);
+ compare("paramDef2 - isInteger", paramDef2.isInteger(), false);
+ compare("paramDef2 - isString", paramDef2.isString(), true);
- compareB("paramDef2 - isJson", paramDef2.isJson(), false);
- compareB("paramDef2 - isBool", paramDef2.isBool(), false);
+ compare("paramDef2 - isJson", paramDef2.isJson(), false);
+ compare("paramDef2 - isBool", paramDef2.isBool(), false);
nlohmann::json js2;
js2["description"] = "Some argument222222";
js2["name"] = "arg2";
js2["restrict"] = "required";
js2["type"] = "string";
- compareS("paramDef2 - toJson", paramDef2.toJson().dump(), js2.dump());
+ compare("paramDef2 - toJson", paramDef2.toJson().dump(), js2.dump());
- compareN("paramDef2 - listOfStringValidators", paramDef2.listOfStringValidators().size(), 1);
- compareN("paramDef2 - listOfIntegerValidators", paramDef2.listOfIntegerValidators().size(), 0);
- compareN("paramDef2 - listOfJsonValidators", paramDef2.listOfJsonValidators().size(), 0);
+ compare("paramDef2 - listOfStringValidators", paramDef2.listOfStringValidators().size(), 1);
+ compare("paramDef2 - listOfIntegerValidators", paramDef2.listOfIntegerValidators().size(), 0);
+ compare("paramDef2 - listOfJsonValidators", paramDef2.listOfJsonValidators().size(), 0);
}
{
@@ -90,81 +90,81 @@ void UnitTestJsonRpc20ParamDef::executeTest() {
.addValidator(new WsjcppValidatorIntegerMinValue(1))
.addValidator(new WsjcppValidatorIntegerMaxValue(1000))
;
- compareS("paramDef3 - name", paramDef3.getName(), "arg3");
- compareS("paramDef3 - getType", paramDef3.getType(), "integer");
- compareS("paramDef3 - getRestrict", paramDef3.getRestrict(), "optional");
- compareS("paramDef3 - getDescription", paramDef3.getDescription(), "Some argument3");
- compareB("paramDef3 - isRequired", paramDef3.isRequired(), false);
- compareB("paramDef3 - isOptional", paramDef3.isOptional(), true);
- compareB("paramDef3 - isInteger", paramDef3.isInteger(), true);
- compareB("paramDef3 - isString", paramDef3.isString(), false);
- compareB("paramDef3 - isJson", paramDef3.isJson(), false);
- compareB("paramDef3 - isBool", paramDef3.isBool(), false);
+ compare("paramDef3 - name", paramDef3.getName(), "arg3");
+ compare("paramDef3 - getType", paramDef3.getType(), "integer");
+ compare("paramDef3 - getRestrict", paramDef3.getRestrict(), "optional");
+ compare("paramDef3 - getDescription", paramDef3.getDescription(), "Some argument3");
+ compare("paramDef3 - isRequired", paramDef3.isRequired(), false);
+ compare("paramDef3 - isOptional", paramDef3.isOptional(), true);
+ compare("paramDef3 - isInteger", paramDef3.isInteger(), true);
+ compare("paramDef3 - isString", paramDef3.isString(), false);
+ compare("paramDef3 - isJson", paramDef3.isJson(), false);
+ compare("paramDef3 - isBool", paramDef3.isBool(), false);
nlohmann::json js3;
js3["description"] = "Some argument3";
js3["name"] = "arg3";
js3["restrict"] = "optional";
js3["type"] = "integer";
- compareS("paramDef3 - toJson", paramDef3.toJson().dump(), js3.dump());
+ compare("paramDef3 - toJson", paramDef3.toJson().dump(), js3.dump());
- compareN("paramDef3 - listOfStringValidators", paramDef3.listOfStringValidators().size(), 0);
- compareN("paramDef3 - listOfIntegerValidators", paramDef3.listOfIntegerValidators().size(), 2);
- compareN("paramDef3 - listOfJsonValidators", paramDef3.listOfJsonValidators().size(), 0);
+ compare("paramDef3 - listOfStringValidators", paramDef3.listOfStringValidators().size(), 0);
+ compare("paramDef3 - listOfIntegerValidators", paramDef3.listOfIntegerValidators().size(), 2);
+ compare("paramDef3 - listOfJsonValidators", paramDef3.listOfJsonValidators().size(), 0);
}
{
WsjcppJsonRpc20ParamDef paramDef4("arg4_1ddd", "Some argument4");
paramDef4.json_().optional();
- compareS("paramDef4 - name", paramDef4.getName(), "arg4_1ddd");
- compareS("paramDef4 - getType", paramDef4.getType(), "json");
- compareS("paramDef4 - getRestrict", paramDef4.getRestrict(), "optional");
- compareS("paramDef4 - getDescription", paramDef4.getDescription(), "Some argument4");
- compareB("paramDef4 - isRequired", paramDef4.isRequired(), false);
- compareB("paramDef4 - isOptional", paramDef4.isOptional(), true);
- compareB("paramDef4 - isInteger", paramDef4.isInteger(), false);
- compareB("paramDef4 - isString", paramDef4.isString(), false);
- compareB("paramDef4 - isJson", paramDef4.isJson(), true);
- compareB("paramDef4 - isBool", paramDef4.isBool(), false);
+ compare("paramDef4 - name", paramDef4.getName(), "arg4_1ddd");
+ compare("paramDef4 - getType", paramDef4.getType(), "json");
+ compare("paramDef4 - getRestrict", paramDef4.getRestrict(), "optional");
+ compare("paramDef4 - getDescription", paramDef4.getDescription(), "Some argument4");
+ compare("paramDef4 - isRequired", paramDef4.isRequired(), false);
+ compare("paramDef4 - isOptional", paramDef4.isOptional(), true);
+ compare("paramDef4 - isInteger", paramDef4.isInteger(), false);
+ compare("paramDef4 - isString", paramDef4.isString(), false);
+ compare("paramDef4 - isJson", paramDef4.isJson(), true);
+ compare("paramDef4 - isBool", paramDef4.isBool(), false);
nlohmann::json js4;
js4["description"] = "Some argument4";
js4["name"] = "arg4_1ddd";
js4["restrict"] = "optional";
js4["type"] = "json";
- compareS("paramDef4 - toJson", paramDef4.toJson().dump(), js4.dump());
+ compare("paramDef4 - toJson", paramDef4.toJson().dump(), js4.dump());
- compareN("paramDef4 - listOfStringValidators", paramDef4.listOfStringValidators().size(), 0);
- compareN("paramDef4 - listOfIntegerValidators", paramDef4.listOfIntegerValidators().size(), 0);
- compareN("paramDef4 - listOfJsonValidators", paramDef4.listOfJsonValidators().size(), 0);
+ compare("paramDef4 - listOfStringValidators", paramDef4.listOfStringValidators().size(), 0);
+ compare("paramDef4 - listOfIntegerValidators", paramDef4.listOfIntegerValidators().size(), 0);
+ compare("paramDef4 - listOfJsonValidators", paramDef4.listOfJsonValidators().size(), 0);
}
{
WsjcppJsonRpc20ParamDef paramDef5("arg5_0", "Some argument5");
paramDef5.bool_().required();
- compareS("paramDef5 - name", paramDef5.getName(), "arg5_0");
- compareS("paramDef5 - getType", paramDef5.getType(), "boolean");
- compareS("paramDef5 - getRestrict", paramDef5.getRestrict(), "required");
- compareS("paramDef5 - getDescription", paramDef5.getDescription(), "Some argument5");
- compareB("paramDef5 - isRequired", paramDef5.isRequired(), true);
- compareB("paramDef5 - isOptional", paramDef5.isOptional(), false);
- compareB("paramDef5 - isInteger", paramDef5.isInteger(), false);
- compareB("paramDef5 - isString", paramDef5.isString(), false);
- compareB("paramDef5 - isJson", paramDef5.isJson(), false);
- compareB("paramDef5 - isBool", paramDef5.isBool(), true);
+ compare("paramDef5 - name", paramDef5.getName(), "arg5_0");
+ compare("paramDef5 - getType", paramDef5.getType(), "boolean");
+ compare("paramDef5 - getRestrict", paramDef5.getRestrict(), "required");
+ compare("paramDef5 - getDescription", paramDef5.getDescription(), "Some argument5");
+ compare("paramDef5 - isRequired", paramDef5.isRequired(), true);
+ compare("paramDef5 - isOptional", paramDef5.isOptional(), false);
+ compare("paramDef5 - isInteger", paramDef5.isInteger(), false);
+ compare("paramDef5 - isString", paramDef5.isString(), false);
+ compare("paramDef5 - isJson", paramDef5.isJson(), false);
+ compare("paramDef5 - isBool", paramDef5.isBool(), true);
nlohmann::json js5;
js5["description"] = "Some argument5";
js5["name"] = "arg5_0";
js5["restrict"] = "required";
js5["type"] = "boolean";
- compareS("paramDef5 - toJson", paramDef5.toJson().dump(), js5.dump());
+ compare("paramDef5 - toJson", paramDef5.toJson().dump(), js5.dump());
- compareN("paramDef5 - listOfStringValidators", paramDef5.listOfStringValidators().size(), 0);
- compareN("paramDef5 - listOfIntegerValidators", paramDef5.listOfIntegerValidators().size(), 0);
- compareN("paramDef5 - listOfJsonValidators", paramDef5.listOfJsonValidators().size(), 0);
+ compare("paramDef5 - listOfStringValidators", paramDef5.listOfStringValidators().size(), 0);
+ compare("paramDef5 - listOfIntegerValidators", paramDef5.listOfIntegerValidators().size(), 0);
+ compare("paramDef5 - listOfJsonValidators", paramDef5.listOfJsonValidators().size(), 0);
}
}
diff --git a/unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.h b/unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.h
deleted file mode 100644
index 397e005..0000000
--- a/unit-tests.wsjcpp/src/unit_test_json_rpc20_param_def.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#ifndef UNIT_TEST_JSON_RPC20_PARAM_DEF_H
-#define UNIT_TEST_JSON_RPC20_PARAM_DEF_H
-
-#endif // UNIT_TEST_JSON_RPC20_PARAM_DEF_H
-
diff --git a/unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.cpp b/unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.cpp
index f34d05c..0fe3adb 100644
--- a/unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.cpp
+++ b/unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.cpp
@@ -1,4 +1,4 @@
-#include "unit_test_json_rpc20_user_session.h"
+#include
#include
#include
#include
@@ -6,6 +6,14 @@
// ---------------------------------------------------------------------
// UnitTestJsonRpc20UserSession
+class UnitTestJsonRpc20UserSession : public WsjcppUnitTestBase {
+ public:
+ UnitTestJsonRpc20UserSession();
+ virtual bool doBeforeTest() override;
+ virtual void executeTest() override;
+ virtual bool doAfterTest() override;
+};
+
REGISTRY_WSJCPP_UNIT_TEST(UnitTestJsonRpc20UserSession)
UnitTestJsonRpc20UserSession::UnitTestJsonRpc20UserSession()
@@ -24,53 +32,53 @@ bool UnitTestJsonRpc20UserSession::doBeforeTest() {
void UnitTestJsonRpc20UserSession::executeTest() {
WsjcppJsonRpc20UserSession session0;
- compareB("is admin (0)", session0.isAdmin(), false);
- compareB("is user (0)", session0.isUser(), false);
- compareB("is tester (0)", session0.isTester(), false);
- compareB("has role (0)", session0.hasRole(), false);
+ compare("is admin (0)", session0.isAdmin(), false);
+ compare("is user (0)", session0.isUser(), false);
+ compare("is tester (0)", session0.isTester(), false);
+ compare("has role (0)", session0.hasRole(), false);
- compareN("User Id (0)", session0.getUserId(), 0);
+ compare("User Id (0)", session0.getUserId(), 0);
- compareS("User Uuid (0)", session0.getUserUuid(), "");
- compareS("User Role (0)", session0.getUserRole(), "");
- compareS("User Name (0)", session0.getUserName(), "");
- compareS("User Email (0)", session0.getUserEmail(), "");
+ compare("User Uuid (0)", session0.getUserUuid(), "");
+ compare("User Role (0)", session0.getUserRole(), "");
+ compare("User Name (0)", session0.getUserName(), "");
+ compare("User Email (0)", session0.getUserEmail(), "");
- compareS("Session Uuid (0)", session0.getSessionUuid(), "");
- compareN("Session Created (0)", session0.getSessionCreated(), 0);
- compareN("Session Updated (0)", session0.getSessionUpdated(), 0);
- compareN("Session Expire At (0)", session0.getSessionExpireAt(), 0);
- compareS("Session Custom (0)", session0.getSessionCustom().dump(), "null");
+ compare("Session Uuid (0)", session0.getSessionUuid(), "");
+ compare("Session Created (0)", session0.getSessionCreated(), 0);
+ compare("Session Updated (0)", session0.getSessionUpdated(), 0);
+ compare("Session Expire At (0)", session0.getSessionExpireAt(), 0);
+ compare("Session Custom (0)", session0.getSessionCustom().dump(), "null");
// test fill role
session0.setUserRole("admin");
- compareB("is admin (1)", session0.isAdmin(), true);
- compareB("is user (1)", session0.isUser(), false);
- compareB("is tester (1)", session0.isTester(), false);
- compareB("has role (1)", session0.hasRole(), true);
- compareS("User Role (1)", session0.getUserRole(), "admin");
+ compare("is admin (1)", session0.isAdmin(), true);
+ compare("is user (1)", session0.isUser(), false);
+ compare("is tester (1)", session0.isTester(), false);
+ compare("has role (1)", session0.hasRole(), true);
+ compare("User Role (1)", session0.getUserRole(), "admin");
session0.setUserRole("user");
- compareB("is admin (2)", session0.isAdmin(), false);
- compareB("is user (2)", session0.isUser(), true);
- compareB("is tester (2)", session0.isTester(), false);
- compareB("has role (2)", session0.hasRole(), true);
- compareS("User Role (2)", session0.getUserRole(), "user");
+ compare("is admin (2)", session0.isAdmin(), false);
+ compare("is user (2)", session0.isUser(), true);
+ compare("is tester (2)", session0.isTester(), false);
+ compare("has role (2)", session0.hasRole(), true);
+ compare("User Role (2)", session0.getUserRole(), "user");
session0.setUserRole("tester");
- compareB("is admin (3)", session0.isAdmin(), false);
- compareB("is user (3)", session0.isUser(), false);
- compareB("is tester (3)", session0.isTester(), true);
- compareB("has role (3)", session0.hasRole(), true);
- compareS("User Role (3)", session0.getUserRole(), "tester");
+ compare("is admin (3)", session0.isAdmin(), false);
+ compare("is user (3)", session0.isUser(), false);
+ compare("is tester (3)", session0.isTester(), true);
+ compare("has role (3)", session0.hasRole(), true);
+ compare("User Role (3)", session0.getUserRole(), "tester");
std::string sUserRole = "custom0";
session0.setUserRole(sUserRole);
- compareB("is admin (4)", session0.isAdmin(), false);
- compareB("is user (4)", session0.isUser(), false);
- compareB("is tester (4)", session0.isTester(), false);
- compareB("has role (4)", session0.hasRole(), true);
- compareS("User Role (4)", session0.getUserRole(), sUserRole);
+ compare("is admin (4)", session0.isAdmin(), false);
+ compare("is user (4)", session0.isUser(), false);
+ compare("is tester (4)", session0.isTester(), false);
+ compare("has role (4)", session0.hasRole(), true);
+ compare("User Role (4)", session0.getUserRole(), sUserRole);
int nUserId = 1000;
std::string sUserUuid = "b5bd63ce-0405-4ef5-8473-552f2729e7e9";
@@ -94,46 +102,46 @@ void UnitTestJsonRpc20UserSession::executeTest() {
session0.setSessionExpireAt(nExpiredAt);
session0.setSessionCustom(jsonCustom);
- compareN("User Id (5)", session0.getUserId(), nUserId);
- compareS("User Uuid (6)", session0.getUserUuid(), sUserUuid);
- compareS("User Name (7)", session0.getUserName(), sUserName);
- compareS("User Email (8)", session0.getUserEmail(), sUserEmail);
- compareS("Session Uuid (9)", session0.getSessionUuid(), sSessionUuid);
- compareN("Session Created (10)", session0.getSessionCreated(), nCreated);
- compareN("Session Updated (11)", session0.getSessionUpdated(), nUpdated);
- compareN("Session Expire At (12)", session0.getSessionExpireAt(), nExpiredAt);
- compareS("Session Custom (13)", session0.getSessionCustom().dump(), sJsonCustom);
+ compare("User Id (5)", session0.getUserId(), nUserId);
+ compare("User Uuid (6)", session0.getUserUuid(), sUserUuid);
+ compare("User Name (7)", session0.getUserName(), sUserName);
+ compare("User Email (8)", session0.getUserEmail(), sUserEmail);
+ compare("Session Uuid (9)", session0.getSessionUuid(), sSessionUuid);
+ compare("Session Created (10)", session0.getSessionCreated(), nCreated);
+ compare("Session Updated (11)", session0.getSessionUpdated(), nUpdated);
+ compare("Session Expire At (12)", session0.getSessionExpireAt(), nExpiredAt);
+ compare("Session Custom (13)", session0.getSessionCustom().dump(), sJsonCustom);
// test full json
nlohmann::json jsonSession = session0.toJson();
WsjcppLog::info(TAG, jsonSession.dump());
- compareS("toJson Session uuid (14)", jsonSession["uuid"], sSessionUuid);
- compareN("toJson Session created (14)", jsonSession["created"], nCreated);
- compareN("toJson Session updated (14)", jsonSession["updated"], nUpdated);
- compareN("toJson Session expire_at (14)", jsonSession["expire_at"], nExpiredAt);
+ compare("toJson Session uuid (14)", jsonSession["uuid"], sSessionUuid);
+ compare("toJson Session created (14)", jsonSession["created"], nCreated);
+ compare("toJson Session updated (14)", jsonSession["updated"], nUpdated);
+ compare("toJson Session expire_at (14)", jsonSession["expire_at"], nExpiredAt);
- compareN("toJson Session user.id (14)", jsonSession["user"]["id"], nUserId);
- compareS("toJson Session user.id (14)", jsonSession["user"]["uuid"], sUserUuid);
- compareS("toJson Session user.id (14)", jsonSession["user"]["name"], sUserName);
- compareS("toJson Session user.id (14)", jsonSession["user"]["role"], sUserRole);
- compareS("toJson Session user.id (14)", jsonSession["user"]["email"], sUserEmail);
+ compare("toJson Session user.id (14)", jsonSession["user"]["id"], nUserId);
+ compare("toJson Session user.id (14)", jsonSession["user"]["uuid"], sUserUuid);
+ compare("toJson Session user.id (14)", jsonSession["user"]["name"], sUserName);
+ compare("toJson Session user.id (14)", jsonSession["user"]["role"], sUserRole);
+ compare("toJson Session user.id (14)", jsonSession["user"]["email"], sUserEmail);
WsjcppJsonRpc20UserSession session1(jsonSession);
- compareB("session1 is admin (0)", session1.isAdmin(), false);
- compareB("session1 is user (0)", session1.isUser(), false);
- compareB("session1 is tester (0)", session1.isTester(), false);
- compareB("session1 has role (0)", session1.hasRole(), true);
- compareN("session1 User Id (0)", session1.getUserId(), nUserId);
- compareS("session1 User Uuid (0)", session1.getUserUuid(), sUserUuid);
- compareS("session1 User Role (0)", session1.getUserRole(), sUserRole);
- compareS("session1 User Name (0)", session1.getUserName(), sUserName);
- compareS("session1 User Email (0)", session1.getUserEmail(), sUserEmail);
- compareS("session1 Session Uuid (0)", session1.getSessionUuid(), sSessionUuid);
- compareN("session1 Session Created (0)", session1.getSessionCreated(), nCreated);
- compareN("session1 Session Updated (0)", session1.getSessionUpdated(), nUpdated);
- compareN("session1 Session Expire At (0)", session1.getSessionExpireAt(), nExpiredAt);
- compareS("session1 Session Custom (0)", session1.getSessionCustom().dump(), sJsonCustom);
+ compare("session1 is admin (0)", session1.isAdmin(), false);
+ compare("session1 is user (0)", session1.isUser(), false);
+ compare("session1 is tester (0)", session1.isTester(), false);
+ compare("session1 has role (0)", session1.hasRole(), true);
+ compare("session1 User Id (0)", session1.getUserId(), nUserId);
+ compare("session1 User Uuid (0)", session1.getUserUuid(), sUserUuid);
+ compare("session1 User Role (0)", session1.getUserRole(), sUserRole);
+ compare("session1 User Name (0)", session1.getUserName(), sUserName);
+ compare("session1 User Email (0)", session1.getUserEmail(), sUserEmail);
+ compare("session1 Session Uuid (0)", session1.getSessionUuid(), sSessionUuid);
+ compare("session1 Session Created (0)", session1.getSessionCreated(), nCreated);
+ compare("session1 Session Updated (0)", session1.getSessionUpdated(), nUpdated);
+ compare("session1 Session Expire At (0)", session1.getSessionExpireAt(), nExpiredAt);
+ compare("session1 Session Custom (0)", session1.getSessionCustom().dump(), sJsonCustom);
// check rewrite data
WsjcppJsonRpc20UserSession session2;
diff --git a/unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.h b/unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.h
deleted file mode 100644
index 1f21535..0000000
--- a/unit-tests.wsjcpp/src/unit_test_json_rpc20_user_session.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef UNIT_TEST_JSON_RPC20_USER_SESSION_H
-#define UNIT_TEST_JSON_RPC20_USER_SESSION_H
-
-#include
-
-class UnitTestJsonRpc20UserSession : public WsjcppUnitTestBase {
- public:
- UnitTestJsonRpc20UserSession();
- virtual bool doBeforeTest() override;
- virtual void executeTest() override;
- virtual bool doAfterTest() override;
-};
-
-#endif // UNIT_TEST_JSON_RPC20_USER_SESSION_H
-
diff --git a/unit-tests.wsjcpp/src/unit_test_parsing_request_params.cpp b/unit-tests.wsjcpp/src/unit_test_parsing_request_params.cpp
index fb753f3..588aad2 100644
--- a/unit-tests.wsjcpp/src/unit_test_parsing_request_params.cpp
+++ b/unit-tests.wsjcpp/src/unit_test_parsing_request_params.cpp
@@ -1,4 +1,4 @@
-#include "unit_test_parsing_request_params.h"
+#include
#include
#include
#include
@@ -75,6 +75,15 @@ void WsjcppJsonRpc20HandlerGameCreate::handle(WsjcppJsonRpc20Request *pRequest)
// ---------------------------------------------------------------------
// UnitTestParsingRequestParams
+
+class UnitTestParsingRequestParams : public WsjcppUnitTestBase {
+ public:
+ UnitTestParsingRequestParams();
+ virtual bool doBeforeTest() override;
+ virtual void executeTest() override;
+ virtual bool doAfterTest() override;
+};
+
REGISTRY_WSJCPP_UNIT_TEST(UnitTestParsingRequestParams)
UnitTestParsingRequestParams::UnitTestParsingRequestParams()
diff --git a/unit-tests.wsjcpp/src/unit_test_parsing_request_params.h b/unit-tests.wsjcpp/src/unit_test_parsing_request_params.h
deleted file mode 100644
index 7a5f099..0000000
--- a/unit-tests.wsjcpp/src/unit_test_parsing_request_params.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef UNIT_TEST_PARSING_REQUEST_PARAMS_H
-#define UNIT_TEST_PARSING_REQUEST_PARAMS_H
-
-#include
-
-class UnitTestParsingRequestParams : public WsjcppUnitTestBase {
- public:
- UnitTestParsingRequestParams();
- virtual bool doBeforeTest() override;
- virtual void executeTest() override;
- virtual bool doAfterTest() override;
-};
-
-#endif // UNIT_TEST_PARSING_REQUEST_PARAMS_H
-
diff --git a/unit-tests.wsjcpp/src/unit_test_request_parse_income_data.cpp b/unit-tests.wsjcpp/src/unit_test_request_parse_income_data.cpp
index 97fed55..607f24d 100644
--- a/unit-tests.wsjcpp/src/unit_test_request_parse_income_data.cpp
+++ b/unit-tests.wsjcpp/src/unit_test_request_parse_income_data.cpp
@@ -1,8 +1,16 @@
-#include "unit_test_request_parse_income_data.h"
+#include
#include
#include
#include
+class UnitTestRequestParseIncomeData : public WsjcppUnitTestBase {
+ public:
+ UnitTestRequestParseIncomeData();
+ virtual bool doBeforeTest() override;
+ virtual void executeTest() override;
+ virtual bool doAfterTest() override;
+};
+
REGISTRY_WSJCPP_UNIT_TEST(UnitTestRequestParseIncomeData)
UnitTestRequestParseIncomeData::UnitTestRequestParseIncomeData()
@@ -28,17 +36,17 @@ void UnitTestRequestParseIncomeData::executeTest() {
{
pFakeClient->clearLastTextMessage();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData empty", pRequest->parseIncomeData(""), false);
+ compare("parseIncomeData empty", pRequest->parseIncomeData(""), false);
std::string sResponse0 = pFakeClient->getLastTextMessage();
nlohmann::json jsonResponse = nlohmann::json::parse(sResponse0);
std::string sErrorMessage = jsonResponse["error"]["message"];
- compareS("parseIncomeData empty. error.message", sErrorMessage, "WRONG_JSON");
+ compare("parseIncomeData empty. error.message", sErrorMessage, "WRONG_JSON");
int nErrorCode = jsonResponse["error"]["code"];
- compareN("parseIncomeData empty. error.code", nErrorCode, 400);
+ compare("parseIncomeData empty. error.code", nErrorCode, 400);
std::string sId = jsonResponse["id"];
- compareS("parseIncomeData empty. id", sId, "unknown_id");
+ compare("parseIncomeData empty. id", sId, "unknown_id");
std::string sMethod = jsonResponse["method"];
- compareS("parseIncomeData empty. method", sMethod, "unknown_method");
+ compare("parseIncomeData empty. method", sMethod, "unknown_method");
delete pRequest;
}
@@ -50,17 +58,17 @@ void UnitTestRequestParseIncomeData::executeTest() {
jsonRequest["method"] = "game_create";
std::string sRequest = jsonRequest.dump();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData missing id", pRequest->parseIncomeData(sRequest), false);
+ compare("parseIncomeData missing id", pRequest->parseIncomeData(sRequest), false);
std::string sResponse = pFakeClient->getLastTextMessage();
nlohmann::json jsonResponse = nlohmann::json::parse(sResponse);
std::string sErrorMessage = jsonResponse["error"]["message"];
- compareS("parseIncomeData missing id. error.message", sErrorMessage, "NOT_FOUND_ID_IN_REQUEST");
+ compare("parseIncomeData missing id. error.message", sErrorMessage, "NOT_FOUND_ID_IN_REQUEST");
int nErrorCode = jsonResponse["error"]["code"];
- compareN("parseIncomeData missing id. error.code", nErrorCode, 400);
+ compare("parseIncomeData missing id. error.code", nErrorCode, 400);
std::string sId = jsonResponse["id"];
- compareS("parseIncomeData missing id. id", sId, "unknown_id");
+ compare("parseIncomeData missing id. id", sId, "unknown_id");
std::string sMethod = jsonResponse["method"];
- compareS("parseIncomeData missing id. method", sMethod, "game_create");
+ compare("parseIncomeData missing id. method", sMethod, "game_create");
delete pRequest;
}
@@ -72,18 +80,18 @@ void UnitTestRequestParseIncomeData::executeTest() {
jsonRequest["id"] = "id1";
std::string sRequest = jsonRequest.dump();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData missing method", pRequest->parseIncomeData(sRequest), false);
+ compare("parseIncomeData missing method", pRequest->parseIncomeData(sRequest), false);
std::string sResponse = pFakeClient->getLastTextMessage();
// std::cout << sResponse << std::endl;
nlohmann::json jsonResponse = nlohmann::json::parse(sResponse);
std::string sErrorMessage = jsonResponse["error"]["message"];
- compareS("parseIncomeData missing method. error. message", sErrorMessage, "NOT_FOUND_METHOD_IN_REQUEST");
+ compare("parseIncomeData missing method. error. message", sErrorMessage, "NOT_FOUND_METHOD_IN_REQUEST");
int nErrorCode = jsonResponse["error"]["code"];
- compareN("parseIncomeData missing method. error. code", nErrorCode, 400);
+ compare("parseIncomeData missing method. error. code", nErrorCode, 400);
std::string sId = jsonResponse["id"];
- compareS("parseIncomeData missing method. id", sId, "id1");
+ compare("parseIncomeData missing method. id", sId, "id1");
std::string sMethod = jsonResponse["method"];
- compareS("parseIncomeData missing method. method", sMethod, "unknown_method");
+ compare("parseIncomeData missing method. method", sMethod, "unknown_method");
delete pRequest;
}
@@ -95,18 +103,18 @@ void UnitTestRequestParseIncomeData::executeTest() {
jsonRequest["method"] = "game_create";
std::string sRequest = jsonRequest.dump();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData missing jsonrpc", pRequest->parseIncomeData(sRequest), false);
+ compare("parseIncomeData missing jsonrpc", pRequest->parseIncomeData(sRequest), false);
std::string sResponse = pFakeClient->getLastTextMessage();
// std::cout << sResponse << std::endl;
nlohmann::json jsonResponse = nlohmann::json::parse(sResponse);
std::string sErrorMessage = jsonResponse["error"]["message"];
- compareS("parseIncomeData missing jsonrpc. error.message", sErrorMessage, "NOT_FOUND_FIELD_JSONRPC_IN_REQUEST");
+ compare("parseIncomeData missing jsonrpc. error.message", sErrorMessage, "NOT_FOUND_FIELD_JSONRPC_IN_REQUEST");
int nErrorCode = jsonResponse["error"]["code"];
- compareN("parseIncomeData missing jsonrpc. error.code", nErrorCode, 400);
+ compare("parseIncomeData missing jsonrpc. error.code", nErrorCode, 400);
std::string sId = jsonResponse["id"];
- compareS("parseIncomeData missing jsonrpc. id", sId, "id1");
+ compare("parseIncomeData missing jsonrpc. id", sId, "id1");
std::string sMethod = jsonResponse["method"];
- compareS("parseIncomeData missing jsonrpc. method", sMethod, "game_create");
+ compare("parseIncomeData missing jsonrpc. method", sMethod, "game_create");
delete pRequest;
}
@@ -119,18 +127,18 @@ void UnitTestRequestParseIncomeData::executeTest() {
jsonRequest["method"] = "game_create";
std::string sRequest = jsonRequest.dump();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData jsonrpc is non string", pRequest->parseIncomeData(sRequest), false);
+ compare("parseIncomeData jsonrpc is non string", pRequest->parseIncomeData(sRequest), false);
std::string sResponse = pFakeClient->getLastTextMessage();
// std::cout << sResponse << std::endl;
nlohmann::json jsonResponse = nlohmann::json::parse(sResponse);
std::string sErrorMessage = jsonResponse["error"]["message"];
- compareS("parseIncomeData jsonrpc is non string. error.message", sErrorMessage, "FIELD_JSONRPC_EXPECTED_AS_STRING_IN_REQUEST");
+ compare("parseIncomeData jsonrpc is non string. error.message", sErrorMessage, "FIELD_JSONRPC_EXPECTED_AS_STRING_IN_REQUEST");
int nErrorCode = jsonResponse["error"]["code"];
- compareN("parseIncomeData jsonrpc is non string. error.code", nErrorCode, 400);
+ compare("parseIncomeData jsonrpc is non string. error.code", nErrorCode, 400);
std::string sId = jsonResponse["id"];
- compareS("parseIncomeData jsonrpc is non string. id", sId, "id1");
+ compare("parseIncomeData jsonrpc is non string. id", sId, "id1");
std::string sMethod = jsonResponse["method"];
- compareS("parseIncomeData jsonrpc is non string. method", sMethod, "game_create");
+ compare("parseIncomeData jsonrpc is non string. method", sMethod, "game_create");
delete pRequest;
}
@@ -143,18 +151,18 @@ void UnitTestRequestParseIncomeData::executeTest() {
jsonRequest["method"] = "game_create";
std::string sRequest = jsonRequest.dump();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData jsonrpc is no 2.0", pRequest->parseIncomeData(sRequest), false);
+ compare("parseIncomeData jsonrpc is no 2.0", pRequest->parseIncomeData(sRequest), false);
std::string sResponse = pFakeClient->getLastTextMessage();
// std::cout << sResponse << std::endl;
nlohmann::json jsonResponse = nlohmann::json::parse(sResponse);
std::string sErrorMessage = jsonResponse["error"]["message"];
- compareS("parseIncomeData jsonrpc is no 2.0. error.message", sErrorMessage, "FIELD_JSONRPC_EXPECTED_2_DOT_0_IN_REQUEST");
+ compare("parseIncomeData jsonrpc is no 2.0. error.message", sErrorMessage, "FIELD_JSONRPC_EXPECTED_2_DOT_0_IN_REQUEST");
int nErrorCode = jsonResponse["error"]["code"];
- compareN("parseIncomeData jsonrpc is no 2.0. error.code", nErrorCode, 400);
+ compare("parseIncomeData jsonrpc is no 2.0. error.code", nErrorCode, 400);
std::string sId = jsonResponse["id"];
- compareS("parseIncomeData jsonrpc is no 2.0. id", sId, "id1");
+ compare("parseIncomeData jsonrpc is no 2.0. id", sId, "id1");
std::string sMethod = jsonResponse["method"];
- compareS("parseIncomeData jsonrpc is no 2.0. method", sMethod, "game_create");
+ compare("parseIncomeData jsonrpc is no 2.0. method", sMethod, "game_create");
delete pRequest;
}
@@ -168,18 +176,18 @@ void UnitTestRequestParseIncomeData::executeTest() {
jsonRequest["params"] = nlohmann::json::array();
std::string sRequest = jsonRequest.dump();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData field params wrong", pRequest->parseIncomeData(sRequest), false);
+ compare("parseIncomeData field params wrong", pRequest->parseIncomeData(sRequest), false);
std::string sResponse = pFakeClient->getLastTextMessage();
// std::cout << sResponse << std::endl;
nlohmann::json jsonResponse = nlohmann::json::parse(sResponse);
std::string sErrorMessage = jsonResponse["error"]["message"];
- compareS("parseIncomeData field params wrong. error.message", sErrorMessage, "FIELD_PARAMS_EXPECTED_AS_OBJECT_IN_REQUEST");
+ compare("parseIncomeData field params wrong. error.message", sErrorMessage, "FIELD_PARAMS_EXPECTED_AS_OBJECT_IN_REQUEST");
int nErrorCode = jsonResponse["error"]["code"];
- compareN("parseIncomeData field params wrong. error.code", nErrorCode, 400);
+ compare("parseIncomeData field params wrong. error.code", nErrorCode, 400);
std::string sId = jsonResponse["id"];
- compareS("parseIncomeData field params wrong. id", sId, "id1");
+ compare("parseIncomeData field params wrong. id", sId, "id1");
std::string sMethod = jsonResponse["method"];
- compareS("parseIncomeData field params wrong. method", sMethod, "game_create");
+ compare("parseIncomeData field params wrong. method", sMethod, "game_create");
delete pRequest;
}
@@ -193,9 +201,9 @@ void UnitTestRequestParseIncomeData::executeTest() {
jsonRequest["params"] = nlohmann::json::object();
std::string sRequest = jsonRequest.dump();
WsjcppJsonRpc20Request *pRequest = new WsjcppJsonRpc20Request(pClient, pWebSocketServer);
- compareB("parseIncomeData success parsing", pRequest->parseIncomeData(sRequest), true);
+ compare("parseIncomeData success parsing", pRequest->parseIncomeData(sRequest), true);
std::string sResponse = pFakeClient->getLastTextMessage();
- compareS("parseIncomeData success parsing. error must be empty", sResponse, "");
+ compare("parseIncomeData success parsing. error must be empty", sResponse, "");
delete pRequest;
}
diff --git a/unit-tests.wsjcpp/src/unit_test_request_parse_income_data.h b/unit-tests.wsjcpp/src/unit_test_request_parse_income_data.h
deleted file mode 100644
index 31412b4..0000000
--- a/unit-tests.wsjcpp/src/unit_test_request_parse_income_data.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef UNIT_TEST_REQUEST_PARSE_INCOME_DATA_H
-#define UNIT_TEST_REQUEST_PARSE_INCOME_DATA_H
-
-#include
-
-class UnitTestRequestParseIncomeData : public WsjcppUnitTestBase {
- public:
- UnitTestRequestParseIncomeData();
- virtual bool doBeforeTest() override;
- virtual void executeTest() override;
- virtual bool doAfterTest() override;
-};
-
-#endif // UNIT_TEST_REQUEST_PARSE_INCOME_DATA_H
-
diff --git a/unit-tests.wsjcpp/src/unit_test_request_server_api.cpp b/unit-tests.wsjcpp/src/unit_test_request_server_api.cpp
index cbba7ad..b8ab835 100644
--- a/unit-tests.wsjcpp/src/unit_test_request_server_api.cpp
+++ b/unit-tests.wsjcpp/src/unit_test_request_server_api.cpp
@@ -1,4 +1,4 @@
-#include "unit_test_request_server_api.h"
+#include
#include
#include
#include
@@ -6,6 +6,14 @@
// ---------------------------------------------------------------------
// UnitTestRequestServerApi
+class UnitTestRequestServerApi : public WsjcppUnitTestBase {
+ public:
+ UnitTestRequestServerApi();
+ virtual bool doBeforeTest() override;
+ virtual void executeTest() override;
+ virtual bool doAfterTest() override;
+};
+
REGISTRY_WSJCPP_UNIT_TEST(UnitTestRequestServerApi)
UnitTestRequestServerApi::UnitTestRequestServerApi()
@@ -36,7 +44,7 @@ void UnitTestRequestServerApi::executeTest() {
requestJson["id"] = "id1";
std::string sRequest = requestJson.dump();
- compareB("Response: check method", pRequest->parseIncomeData(sRequest), true);
+ compare("Response: check method", pRequest->parseIncomeData(sRequest), true);
pHandlerServerApi->handle(pRequest);
@@ -47,17 +55,17 @@ void UnitTestRequestServerApi::executeTest() {
std::string sMethod = respJson["method"];
std::string sId = respJson["id"];
std::string sJsonRpc = respJson["jsonrpc"];
- compareS("Response: check method", sMethod, "server_api");
- compareS("Response: check id", sId, "id1");
- compareS("Response: check jsonrpc", sJsonRpc, "2.0");
+ compare("Response: check method", sMethod, "server_api");
+ compare("Response: check id", sId, "id1");
+ compare("Response: check jsonrpc", sJsonRpc, "2.0");
std::string sVersion = respJson["result"]["version"];
- compareS("Response: check result.version", sVersion, std::string(WSJCPP_APP_VERSION));
+ compare("Response: check result.version", sVersion, std::string(WSJCPP_APP_VERSION));
int nDataLength = respJson["result"]["data_length"];
int nExpectedDataLength = respJson["result"]["data"].size();
- compareN("Response: check result.data_length", nDataLength, nExpectedDataLength);
+ compare("Response: check result.data_length", nDataLength, nExpectedDataLength);
int nId = 1;
for (int i = 0; i < nExpectedDataLength; i++) {
@@ -73,16 +81,16 @@ void UnitTestRequestServerApi::executeTest() {
bool bAccessTester = data0Json["access"]["tester"];
bool bAccessAdmin = data0Json["access"]["admin"];
- compareB("Response: check result.data[0].access.unauthorized", bAccessUnauthorized, true);
- compareB("Response: check result.data[0].access.user", bAccessUser, true);
- compareB("Response: check result.data[0].access.tester", bAccessTester, true);
- compareB("Response: check result.data[0].access.admin", bAccessAdmin, true);
+ compare("Response: check result.data[0].access.unauthorized", bAccessUnauthorized, true);
+ compare("Response: check result.data[0].access.user", bAccessUser, true);
+ compare("Response: check result.data[0].access.tester", bAccessTester, true);
+ compare("Response: check result.data[0].access.admin", bAccessAdmin, true);
sMethod = data0Json["method"];
- compareS("Response: check result.data[0].method", sMethod, "server_api");
+ compare("Response: check result.data[0].method", sMethod, "server_api");
std::string sDescription = data0Json["description"];
- compareS("Response: check result.data[0].method", sDescription, pHandlerServerApi->getDescription());
+ compare("Response: check result.data[0].method", sDescription, pHandlerServerApi->getDescription());
}
// ---------------------------------------------------------------------
diff --git a/unit-tests.wsjcpp/src/unit_test_request_server_api.h b/unit-tests.wsjcpp/src/unit_test_request_server_api.h
deleted file mode 100644
index 6ab7fd7..0000000
--- a/unit-tests.wsjcpp/src/unit_test_request_server_api.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef UNIT_TEST_REQUEST_SERVER_API_H
-#define UNIT_TEST_REQUEST_SERVER_API_H
-
-#include
-
-class UnitTestRequestServerApi : public WsjcppUnitTestBase {
- public:
- UnitTestRequestServerApi();
- virtual bool doBeforeTest() override;
- virtual void executeTest() override;
- virtual bool doAfterTest() override;
-};
-
-#endif // UNIT_TEST_REQUEST_SERVER_API_H
-
diff --git a/wsjcpp.yml b/wsjcpp.yml
index bdeb333..2c4a389 100644
--- a/wsjcpp.yml
+++ b/wsjcpp.yml
@@ -1,33 +1,38 @@
name: "wsjcpp-jsonrpc20"
-version: v0.0.3
+version: v0.0.4
cmake_minimum_required: "3.0"
cmake_cxx_standard: "11"
description: "Implementation of JsonRPC 2.0"
authors:
- name: "Evgenii Sopov"
email: "mrseakg@gmail.com"
+
origins:
- address: "https://sea-kg.com/wsjcpp-package-registry/"
type: "package-registry"
+
keywords:
- "c++"
dependencies:
- name: "wsjcpp-core"
- version: "v0.2.0"
+ version: "v0.2.1"
url: "https://github.com/wsjcpp/wsjcpp-core:master"
origin: "https://github.com/"
installation-dir: "./src.wsjcpp/wsjcpp_core"
+ installation-datetime: "Sat, 03 Oct 2020 12:31:01 GMT"
- name: "nlohmann/json"
version: "v3.9.1"
url: "https://github.com/nlohmann/json:develop"
origin: "https://github.com/"
installation-dir: "./src.wsjcpp/nlohmann_json"
+ installation-datetime: "Fri, 02 Oct 2020 04:29:29 GMT"
- name: "wsjcpp-validators"
version: "v0.1.2"
url: "https://github.com/wsjcpp/wsjcpp-validators:master"
origin: "https://github.com/"
installation-dir: "./src.wsjcpp/wsjcpp_validators"
+ installation-datetime: "Sat, 03 Oct 2020 12:46:55 GMT"
distribution:
- source-file: "src/wsjcpp_jsonrpc20.h"
@@ -45,6 +50,18 @@ distribution:
- source-file: "scripts.wsjcpp/generate.WsjcppJsonRpc20Handler"
target-file: "generate.WsjcppJsonRpc20Handler"
type: "safe-scripting-generate"
+ - source-file: "src/wsjcpp_jsonrpc20_export_cli_webjs.h"
+ target-file: "wsjcpp_jsonrpc20_export_cli_webjs.h"
+ type: "source-code"
+ - source-file: "src/wsjcpp_jsonrpc20_export_cli_webjs.cpp"
+ target-file: "wsjcpp_jsonrpc20_export_cli_webjs.cpp"
+ type: "source-code"
+ - source-file: "src/wsjcpp_jsonrpc20_export_cli_base.h"
+ target-file: "wsjcpp_jsonrpc20_export_cli_base.h"
+ type: "source-code"
+ - source-file: "src/wsjcpp_jsonrpc20_export_cli_base.cpp"
+ target-file: "wsjcpp_jsonrpc20_export_cli_base.cpp"
+ type: "source-code"
unit-tests:
cases: