TEST(ByteArrayTest, DefaultConstruction) { ByteArray ba; ASSERT_TRUE(ba.isNull()); ASSERT_TRUE(ba.isEmpty()); ASSERT_EQ(ba.length(), 0); ByteArray clone = ba; ASSERT_TRUE(clone.isNull()); ASSERT_TRUE(clone.isEmpty()); ASSERT_EQ(clone.length(), 0); }
void Process::write(const ByteArray& data) { if (!data.isEmpty() && mStdIn[1] != -1) { mStdInBuffer.push_back(data); handleInput(mStdIn[1]); } }
TEST(ByteArrayTest, Clear) { ByteArray ba = "This is a test"; ba.clear(); ASSERT_FALSE(ba.isNull()); ASSERT_TRUE(ba.isEmpty()); ba = "This is a test"; ByteArray clone = ba; ba.clear(); ASSERT_FALSE(ba.isNull()); ASSERT_TRUE(ba.isEmpty()); ASSERT_FALSE(clone.isNull()); ASSERT_FALSE(clone.isEmpty()); clone.clear(); ASSERT_FALSE(clone.isNull()); ASSERT_TRUE(clone.isEmpty()); }
void GenericHID::onMicrocontrollerImportAndProgram() { // Get the filename QString sFilename = QFileDialog::getOpenFileName( this, "Open GenericHID device", m_sLastExportFile, "Microcontroller Config Description file (*.mcd);;All files (*)" ); if ( sFilename.isNull() || sFilename.isEmpty() ) return; // read the device xml QFile file(sFilename.toAscii().constData()); if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) { QMessageBox::critical( this, "Can't open", QString("Failed to open file '%1':%2").arg(sFilename).arg(file.errorString()) ); return; } m_sLastExportFile = sFilename; QString s; { // Unclear on how to close a file when the stream is using it, hence the scope. QTextStream stream(&file); s = stream.readAll(); } file.close(); if ( s.isEmpty() ) { QMessageBox msg(QMessageBox::Critical, "Errors Found", QString("Data file '%1' is empty, or failed to read file (%2)").arg(sFilename).arg(file.errorString()), QMessageBox::Ok, this ); msg.exec(); return; } // make eeprom MakeEEPROM eeprom; if ( !eeprom.loadXML( s ) ) { QMessageBox::critical( this, "Error", eeprom.lastError() ); return; } ByteArray buf = eeprom.makeEEPROM(); if ( buf.isEmpty() ) { QMessageBox::critical( this, "Error", eeprom.lastError() ); return; } QString sIntelHex = MakeEEPROM::MakeIntelHexFormat( DYNAMIC_HIDDATA_ADDRESS, buf ); DoProgram( sIntelHex ); }
TEST(ByteArrayTest, ConstructionFromSharedCopy) { ByteArray ba("This is a test"); ByteArray clone = ba; ASSERT_FALSE(ba.isNull()); ASSERT_FALSE(ba.isEmpty()); ASSERT_EQ(ba.length(), 14); ASSERT_STRCASEEQ(ba, "This is a test"); ASSERT_FALSE(clone.isNull()); ASSERT_FALSE(clone.isEmpty()); ASSERT_EQ(clone.length(), 14); ASSERT_STRCASEEQ(clone, "This is a test"); }
Path Process::findCommand(const ByteArray& command) { if (command.isEmpty() || command.at(0) == '/') return command; const char* path = getenv("PATH"); if (!path) return Path(); bool ok; const List<ByteArray> paths = ByteArray(path).split(':'); for (List<ByteArray>::const_iterator it = paths.begin(); it != paths.end(); ++it) { const Path ret = Path::resolved(command, *it, &ok); if (ok && !access(ret.nullTerminated(), R_OK | X_OK)) return ret; } return Path(); }
void GenericHID::onMicrocontrollerProgram() { RetrieveProperties(); // Verify QString sError; if ( !m_pScene->VerifyShapes( sError ) ) { QMessageBox msg(QMessageBox::Critical, "Errors Found", "Errors were found processing the device configuration", QMessageBox::Ok, this ); msg.setDetailedText( sError ); msg.exec(); return; } // make xml QString s = m_pScene->MakeDeviceXML(); if ( s.isEmpty() ) { QMessageBox msg(QMessageBox::Critical, "Errors Found", "Failed to create the device configuration", QMessageBox::Ok, this ); msg.exec(); return; } // make eeprom MakeEEPROM eeprom; if ( !eeprom.loadXML( s ) ) { QMessageBox::critical( this, "Error", eeprom.lastError() ); return; } ByteArray buf = eeprom.makeEEPROM(); if ( buf.isEmpty() ) { QMessageBox::critical( this, "Error", eeprom.lastError() ); return; } QString sIntelHex = MakeEEPROM::MakeIntelHexFormat( DYNAMIC_HIDDATA_ADDRESS, buf ); LOG_DEBUG( m_Logger, "Program HexFile - " ); LOG_DEBUG( m_Logger, sIntelHex ); // program DoProgram( sIntelHex ); }
ByteArray::ByteArray(const ByteArray &src) { init(); if(!src.isEmpty()) { setData(src.getData(), src.size()); } }
ByteArray cursorToString(CXCursor cursor, unsigned flags) { const CXCursorKind kind = clang_getCursorKind(cursor); ByteArray ret; ret.reserve(256); ret += eatString(clang_getCursorKindSpelling(kind)); if (clang_isInvalid(kind)) return ret; switch (RTags::cursorType(kind)) { case Reference: ret += " r"; break; case Cursor: ret += " c"; break; case Other: ret += " o"; break; case Include: ret += " i"; break; } const ByteArray name = eatString(clang_getCursorDisplayName(cursor)); const ByteArray other = eatString(clang_getCursorSpelling(cursor)); if (!name.isEmpty()) ret += " " + name; if (other != name && !other.isEmpty()) ret += " " + other; if (clang_isCursorDefinition(cursor)) ret += " def"; if (flags & IncludeUSR) ret += " " + eatString(clang_getCursorUSR(cursor)); CXFile file; unsigned off, line, col; //presumedLine, presumedCol, instantiationLoc, expansionLoc; CXSourceLocation location = clang_getCursorLocation(cursor); clang_getSpellingLocation(location, &file, &line, &col, &off); // clang_getPresumedLocation(location, 0, &presumedLine, &presumedCol); // clang_getInstantiationLocation(location, 0, 0, 0, &instantiationLoc); // clang_getExpansionLocation(location, 0, 0, 0, &expansionLoc); const Str fileName(clang_getFileName(file)); if (fileName.data() && *fileName.data()) { ret += ' '; ret += fileName.data(); ret += ','; ret += ByteArray::number(off); if (flags & IncludeRange) { ret += " ("; CXSourceRange range = clang_getCursorExtent(cursor); unsigned start, end; clang_getSpellingLocation(clang_getRangeStart(range), 0, 0, 0, &start); clang_getSpellingLocation(clang_getRangeEnd(range), 0, 0, 0, &end); ret += ByteArray::number(start); ret += '-'; ret += ByteArray::number(end); ret += ')'; } // if (presumedLine != line || presumedCol != col) // ret += ByteArray::snprintf<32>("presumed: %d:%d", presumedLine, presumedCol); // if (instantiationLoc != off) // ret += ByteArray::snprintf<32>("instantiation: %d", instantiationLoc); // if (expansionLoc != off) // ret += ByteArray::snprintf<32>("expansion: %d", expansionLoc); } return ret; }