void TestLogEngineConstructor_SeveralInstances () { LogFileBackup (); // scope to construct+destruct the object. { LogEngine logEngine (LOG_DEVELOPER, "TS1"); { LogEngine logEngine2 (LOG_DEVELOPER, "TS2"); } std::fstream testFile; testFile.open (TestLogFile.c_str (), std::fstream::in); char buf[4096]; testFile.read (buf, 4096); std::string bufString (buf); MAssert (bufString.find ("TS1") != std::string::npos); MAssert (bufString.find ("TS2") != std::string::npos); MAssert (bufString.find ("2 log engine") != std::string::npos); MAssert (bufString.find ("s 0 log engine") == std::string::npos); } std::fstream testFile; testFile.open (TestLogFile.c_str (), std::fstream::in); char buf[4096]; testFile.read (buf, 4096); std::string bufString (buf); MAssert (bufString.find ("s 0 log engine") != std::string::npos); LogFileRestore (); }
// (sys 'any ['any]) -> sym any doSys(any x) { any y; y = evSym(x = cdr(x)); { char nm[bufSize(y)]; bufString(y,nm); if (!isCell(x = cdr(x))) return mkStr(getenv(nm)); y = evSym(x); { char val[bufSize(y)]; bufString(y,val); return setenv(nm,val,1)? Nil : y; } } }
void XmlTree::loadFromDataSource( DataSourceRef dataSource, XmlTree *result, const XmlTree::ParseOptions &parseOptions ) { auto buf = dataSource->getBuffer(); size_t dataSize = buf->getSize(); unique_ptr<char[]> bufString( new char[dataSize+1] ); memcpy( bufString.get(), buf->getData(), buf->getSize() ); bufString.get()[dataSize] = 0; rapidxml::xml_document<> doc; // character type defaults to char if( parseOptions.getParseComments() ) doc.parse<rapidxml::parse_comment_nodes | rapidxml::parse_doctype_node>( bufString.get() ); else doc.parse<rapidxml::parse_doctype_node>( bufString.get() ); parseItem( doc, NULL, result, parseOptions ); result->setNodeType( NODE_DOCUMENT ); // call this after parse - constructor replaces it }
// (call 'any ..) -> flg any doCall(any ex) { pid_t pid; any x, y; int res, i, ac = length(x = cdr(ex)); char *av[ac+1]; if (ac == 0) return Nil; av[0] = alloc(NULL, pathSize(y = evSym(x))), pathString(y, av[0]); for (i = 1; isCell(x = cdr(x)); ++i) av[i] = alloc(NULL, bufSize(y = evSym(x))), bufString(y, av[i]); av[ac] = NULL; flushAll(); if ((pid = fork()) == 0) { setpgid(0,0); execvp(av[0], av); execError(av[0]); } i = 0; do free(av[i]); while (++i < ac); if (pid < 0) err(ex, NULL, "fork"); setpgid(pid,0); if (Termio) tcsetpgrp(0,pid); for (;;) { while (waitpid(pid, &res, WUNTRACED) < 0) { if (errno != EINTR) err(ex, NULL, "wait pid"); if (*Signal) sighandler(ex); } if (Termio) tcsetpgrp(0,getpgrp()); if (!WIFSTOPPED(res)) return res == 0? T : Nil; load(NULL, '+', Nil); if (Termio) tcsetpgrp(0,pid); kill(pid, SIGCONT); } }
void TestLogEngineConstructor_FileCreation () { LogFileBackup (); // scope to construct+destruct the object. { LogEngine logEngine (LOG_DEVELOPER, "TST"); } std::fstream testFile; testFile.open (TestLogFile.c_str (), std::fstream::in); char buf[4096]; testFile.getline (buf, 4096); std::string bufString (buf); MAssert (bufString.find ("TST") != std::string::npos); MAssert (bufString.find ("LogFile created") != std::string::npos); LogFileRestore (); }
void TestFormat_filter_gt () { LogFileBackup (); // scope to construct+destruct the object. { LogEngine logEngine (LOG_ENDUSER, "TST"); logEngine.format (LOG_WARNING, "s:%s d:%d %c", "a string", 42, '#'); } std::fstream testFile; testFile.open (TestLogFile.c_str (), std::fstream::in); char buf[4096]; testFile.getline (buf, 4096); // eat line testFile.getline (buf, 4096); // read line std::string bufString (buf); MAssert (bufString.find ("s:a string d:42 #") != std::string::npos); LogFileRestore (); }
void TestPut_filter_eq () { LogFileBackup (); // scope to construct+destruct the object. { LogEngine logEngine (LOG_WARNING, "TST"); logEngine.format (LOG_WARNING, "logtext"); } std::fstream testFile; testFile.open (TestLogFile.c_str (), std::fstream::in); char buf[4096]; testFile.getline (buf, 4096); // read line std::string bufString (buf); MAssert (bufString.find ("logtext") != std::string::npos); LogFileRestore (); }
// (term-decode 'sym) -> num | Nil any plisp_term_decode(any ex) { any x, y; unsigned i, total = sizeof(term_key_names) / sizeof(char*); x = cdr(ex), y = EVAL(car(x)); NeedSymb(ex, y); char key[bufSize(y)]; bufString(y, key); if (*key != 'K') return Nil; for (i = 0; i < total; i++) if (!strcmp(key, term_key_names[i])) break; if (i == total) return Nil; else return box(i + TERM_FIRST_KEY); }
std::string ResourceEngineAndroid::loadLevel(std::string const& levelName) { //logging::Fatal() << " not implemented"; if (!assertAssetManager()) return ""; const std::string fileName(getLevelPrefix() + levelName + ".xml"); AAsset * asset = AAssetManager_open(m_assetManager, fileName.c_str(), AASSET_MODE_STREAMING); if (asset == nullptr) { logging::Fatal() << "Asset with name " << fileName << " could not be loaded."; return ""; } constexpr size_t buffer_size = 1024; int bytes_read; char buffer[buffer_size]; std::string textFileString; while (true) { bytes_read = AAsset_read(asset, &buffer, buffer_size); if (bytes_read < 0) { logging::Fatal() << "Error while reading from file " << fileName; return ""; } else { std::string bufString(buffer); bufString.resize(bytes_read); textFileString.append(bufString); // at the end ! if (bytes_read < buffer_size) break; } } logging::Info() << "Completed reading of file " << fileName; return textFileString; }
void TestLogEngineConstructor_ComponentName () { char *componentNames[] = { "111", "22", "3", "", "!!!", "6 6", "7\07", "888888888888888888888888888888888888888888888888" "888888888888888888888888888888888888888888888888" "88888888888888888888888888888888888888888888888", "дс~", "ten" }; for (int n = 0; n < 10; ++n) { LogFileBackup (); // scope to construct+destruct the object. { LogEngine logEngine (LOG_DEVELOPER, componentNames[n]); } std::fstream testFile; testFile.open (TestLogFile.c_str (), std::fstream::in); char buf[4096]; testFile.getline (buf, 4096); std::string bufString (buf); std::string name (componentNames[n]); name.resize (3, ' '); MAssert (bufString.find (name) != std::string::npos); LogFileRestore (); } }
// (tmr-decode 'sym) -> num any tmr_decode(any ex) { char* pend; long res; any x, y; x = cdr(ex), y = EVAL(car(x)); NeedSym(ex, y); char key[bufSize(y)]; bufString(y, key); if (strlen(key) > MAX_VTIMER_NAME_LEN || strlen(key) < MIN_VTIMER_NAME_LEN) return box(0); if (strncmp(key, "VIRT", 4)) return box(0); res = strtol(key + 4, &pend, 10); if (*pend != '\0') return box(0); if (res >= VTMR_NUM_TIMERS) return box(0); return box(res + VTMR_FIRST_ID); }
void TestLogEngineConstructor_Filter () { LogFileBackup (); // scope to construct+destruct the object. { LogEngine logEngine (LOG_ERROR, "TST"); } std::fstream testFile; testFile.open (TestLogFile.c_str (), std::fstream::in); char buf[4096]; testFile.getline (buf, 4096); std::string bufString (buf); // there should be no text like this in the file with this filter. MAssert (bufString.find ("TST") == std::string::npos); MAssert (bufString.find ("LogFile created") == std::string::npos); LogFileRestore (); }