Remove to migrate to QTestLib

This commit is contained in:
alqualos 2011-09-04 12:59:39 +00:00
parent 5b34c92e93
commit de2e5b4104
14 changed files with 0 additions and 500 deletions

View file

@ -1,2 +0,0 @@
add_executable(checksum main.cpp)
target_link_libraries(checksum quazip)

View file

@ -1,14 +0,0 @@
include (../../includes.pri)
TEMPLATE = app
CONFIG += qt warn_on console
QT -= gui
DEPENDPATH += .
INCLUDEPATH += . ../../
LIBS += -L../../bin -lquazip
# Input
SOURCES += main.cpp

View file

@ -1,53 +0,0 @@
#include <QFile>
#include <QTextStream>
#include <stdlib.h>
#include <stdio.h>
#include <quazip/quachecksum32.h>
#include <quazip/quaadler32.h>
#include <quazip/quacrc32.h>
bool isSmallFile(const QFile &file)
{
return file.size() < 1*1024*1024; // < 1 MB
}
int main(int argc, char* argv[])
{
QTextStream console(stdout);
if(argc != 2)
{
console << "usage: checksum filepath\n";
return -1;
}
QFile file(argv[1]);
if( !file.open(QFile::ReadOnly) )
{
console << "Coulden't open file " << argv[1] << '\n';
return -2;
}
quint32 resoult;
QuaChecksum32 *checksum = new QuaCrc32();// or QuaAdler32
if(isSmallFile(file)) //then calculate the checksum in one step
{
resoult = checksum->calculate(file.readAll());
}
else //then calculate the checksum by streaming
{
const quint64 bufSize = 500*1024; //500 kB
while(!file.atEnd())
{
checksum->update(file.read(bufSize));
}
resoult = checksum->value();
}
console << "checksum: " << hex << resoult << '\n';
return 0;
}

View file

@ -1,2 +0,0 @@
add_executable(jlcompress main.cpp)
target_link_libraries(jlcompress quazip)

View file

@ -1,14 +0,0 @@
include (../../includes.pri)
TEMPLATE = app
CONFIG += qt warn_on console
QT -= gui
DEPENDPATH += .
INCLUDEPATH += . ../../
LIBS += -L../../bin -lquazip
# Input
SOURCES += main.cpp

View file

@ -1,108 +0,0 @@
#include <QtCore>
#include <quazip/JlCompress.h>
#include <quazip/quazip.h>
int main() {
QStringList lst;
////////////////
// Compression
qDebug() << "Compression:";
// Compress a single file
qDebug() << "Compression of main.cpp in tmp/example1.zip:" \
<< JlCompress::compressFile("tmp/example1.zip","main.cpp");
// Compress a list of files
lst.clear();
lst << "main.cpp" << "Makefile" << "jlcompress.pro";
qDebug() << "Compression of " << lst << " in tmp/example2.zip: " \
<< JlCompress::compressFiles("tmp/example2.zip",lst);
// Compress a dir (current dir)
qDebug() << "Compression of all files and subdir in tmp/example3.zip:" \
<< JlCompress::compressDir("tmp/example3.zip");
///////////////
// Extraction
qDebug() << "\n\nExtraction:";
// Print file's names in the compressed file
qDebug() << "Files in tmp/example3.zip (all):";
qDebug() << JlCompress::getFileList("tmp/example3.zip");
// Extract a file
qDebug() << "\nFile extract from tmp/example1.zip (main.cpp):";
qDebug() << JlCompress::extractFile("tmp/example1.zip","main.cpp","tmp/ext1/main.cpp");
// Extract a list of files
lst.clear();
lst << "main.cpp" << "Makefile";
qDebug() << "\nFiles extract from tmp/example2.zip " << lst << ":";
qDebug() << JlCompress::extractFiles("tmp/example2.zip",lst,"tmp/ext2");
// Extract a dir
qDebug() << "\nFiles extracted from tmp/example3.zip (all):";
qDebug() << JlCompress::extractDir("tmp/example3.zip","tmp/ext3");
return 0;
}
/*
int compressFolder(QString folder, QString filename, bool subfolders = true) {
// Se la cartella non esiste o non è una cartella
if (!QFileInfo(folder).isDir()) return -ERR_IS_NOT_DIRECTORY;
// Pero goni file presente nella cartella
QFileInfoList files = QDir(folder).entryInfoList();
QFile inFile;
foreach(QFileInfo file, files) {
// Controllare se il file è lo stesso che si crea
if (file==QFile(filename)) continue;
// Se è un file
if (file.isFile()) {
// Apro il file
inFile.setFileName(file.fileName());
if(!inFile.open(QIODevice::ReadOnly)) return -ERR_CANT_OPEN_FILE;
}
// Se è una sotto cartella
if (file.isDir() && subfolders) {
}
}
QFile inFile;
QuaZipFile outFile(&zip);
char c;
foreach(QFileInfo file, files) {
if(!file.isFile()||file.fileName()=="test.zip") continue;
inFile.setFileName(file.fileName());
if(!inFile.open(QIODevice::ReadOnly)) {
qWarning("testCreate(): inFile.open(): %s", inFile.errorString().toLocal8Bit().constData());
return false;
}
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(inFile.fileName(), inFile.fileName()))) {
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return false;
}
while(inFile.getChar(&c)&&outFile.putChar(c));
if(outFile.getZipError()!=UNZ_OK) {
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return false;
}
outFile.close();
if(outFile.getZipError()!=UNZ_OK) {
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return false;
}
inFile.close();
}
}
*/

View file

@ -1 +0,0 @@
out *.zip unzip

View file

@ -1,2 +0,0 @@
add_executable(unzip main.cpp)
target_link_libraries(unzip quazip)

View file

@ -1,201 +0,0 @@
#include <QDir>
#include <QFile>
#include <quazip/quazip.h>
#include <quazip/quazipfile.h>
/* A simple test program. Requires "test.zip" and writable "out"
* directory to be present in the current directory.
*
* To test unicode-aware case sensitivity, see testCase() function.
*/
// test reading archive
bool testRead()
{
QFile zipFile("test.zip");
QuaZip zip(&zipFile);
if(!zip.open(QuaZip::mdUnzip)) {
qWarning("testRead(): zip.open(): %d", zip.getZipError());
return false;
}
zip.setFileNameCodec("IBM866");
printf("%d entries\n", zip.getEntriesCount());
printf("Global comment: %s\n", zip.getComment().toLocal8Bit().constData());
QuaZipFileInfo info;
printf("name\tcver\tnver\tflags\tmethod\tctime\tCRC\tcsize\tusize\tdisknum\tIA\tEA\tcomment\textra\n");
QuaZipFile file(&zip);
QFile out;
QString name;
char c;
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
if(!zip.getCurrentFileInfo(&info)) {
qWarning("testRead(): getCurrentFileInfo(): %d\n", zip.getZipError());
return false;
}
printf("%s\t%hu\t%hu\t%hu\t%hu\t%s\t%u\t%u\t%u\t%hu\t%hu\t%u\t%s\t%s\n",
info.name.toLocal8Bit().constData(),
info.versionCreated, info.versionNeeded, info.flags, info.method,
info.dateTime.toString(Qt::ISODate).toLocal8Bit().constData(),
info.crc, info.compressedSize, info.uncompressedSize, info.diskNumberStart,
info.internalAttr, info.externalAttr,
info.comment.toLocal8Bit().constData(), info.extra.constData());
if(!file.open(QIODevice::ReadOnly)) {
qWarning("testRead(): file.open(): %d", file.getZipError());
return false;
}
name=file.getActualFileName();
if(file.getZipError()!=UNZ_OK) {
qWarning("testRead(): file.getFileName(): %d", file.getZipError());
return false;
}
QString dirn = "out/" + name;
if (name.contains('/')) { // subdirectory support
// there must be a more elegant way of doing this
// but I couldn't find anything useful in QDir
dirn.chop(dirn.length() - dirn.lastIndexOf("/"));
QDir().mkpath(dirn);
}
out.setFileName("out/" + name);
out.open(QIODevice::WriteOnly);
char buf[4096];
int len = 0;
while (file.getChar(&c)) {
// we could just do this, but it's about 40% slower:
// out.putChar(c);
buf[len++] = c;
if (len >= 4096) {
out.write(buf, len);
len = 0;
}
}
if (len > 0) {
out.write(buf, len);
}
out.close();
if(file.getZipError()!=UNZ_OK) {
qWarning("testRead(): file.getFileName(): %d", file.getZipError());
return false;
}
if(!file.atEnd()) {
qWarning("testRead(): read all but not EOF");
return false;
}
file.close();
if(file.getZipError()!=UNZ_OK) {
qWarning("testRead(): file.close(): %d", file.getZipError());
return false;
}
}
zip.close();
if(zip.getZipError()!=UNZ_OK) {
qWarning("testRead(): zip.close(): %d", zip.getZipError());
return false;
}
return true;
}
// test pos(), size(), csize(), usize(), ungetChar(), bytesAvailable()
bool testPos()
{
QuaZip zip("test.zip");
if(!zip.open(QuaZip::mdUnzip)) {
qWarning("testPos(): zip.open(): %d", zip.getZipError());
return false;
}
if(!zip.goToFirstFile()) {
qWarning("testPos(): zip.goToFirstFile(): %d", zip.getZipError());
return false;
}
QuaZipFile file(&zip);
int method;
if(!file.open(QIODevice::ReadOnly, &method, NULL, true)) {
qWarning("testPos(): file.open(raw): %d", file.getZipError());
return false;
}
QByteArray array=file.readAll();
if(array.isEmpty()) {
qWarning("testPos(): file.readAll(): %d", file.getZipError());
return false;
}
qint64 pos=file.pos();
if(pos!=file.size()||file.size()!=file.csize()) {
qWarning("testPos(): pos=%Ld, file.size()=%Ld, file.csize()=%Ld", pos, file.size(), file.csize());
return false;
}
char last=array.at(array.size()-1);
file.ungetChar(last);
char next;
if(!file.getChar(&next)) {
qWarning("testPos(): file.getChar(): %d", file.getZipError());
return false;
}
if(last!=next) {
qWarning("testPos(): ungot %d, got %d", (int)(uchar)last, (int)(uchar)next);
return false;
}
if(file.pos()!=pos) { // position should not change
qWarning("testPos(): position changed: old pos=%Ld, new pos=%Ld", pos, file.pos());
return false;
}
file.close();
if(zip.getZipError()!=UNZ_OK) {
qWarning("testPos(): file.close(raw): %d", file.getZipError());
return false;
}
if(!file.open(QIODevice::ReadOnly, &method, NULL, false)) {
qWarning("testPos(): file.open(): %d", file.getZipError());
return false;
}
array=file.readAll();
pos=file.pos();
if(pos!=file.size()||file.size()!=file.usize()) {
qWarning("testPos(): pos=%Ld, file.size()=%Ld, file.usize()=%Ld", pos, file.size(), file.usize());
return false;
}
file.close();
if(zip.getZipError()!=UNZ_OK) {
qWarning("testPos(): file.close(): %d", file.getZipError());
return false;
}
zip.close();
if(zip.getZipError()!=UNZ_OK) {
qWarning("testPos(): zip.close(): %d", zip.getZipError());
return false;
}
return true;
}
// test unicode-aware case sensitivity
// change the name and file name codec below before compiling
bool testCase()
{
QString name=QString::fromUtf8("01_КАФЕ НА ТРОТУАРЕ.OGG");
QuaZip zip("test.zip");
if(!zip.open(QuaZip::mdUnzip)) {
qWarning("testCase(): zip.open(): %d", zip.getZipError());
return false;
}
zip.setFileNameCodec("IBM866");
if(!zip.setCurrentFile(name, QuaZip::csInsensitive)) {
if(zip.getZipError()==UNZ_OK)
qWarning("testCase(): setCurrentFile(): check the file name");
else
qWarning("testCase(): setCurrentFile(): %d", zip.getZipError());
return false;
}
if(zip.setCurrentFile(name, QuaZip::csSensitive)) {
qWarning("testCase(): setCurrentFile(): sets even if the case is wrong");
return false;
}
zip.close();
return true;
}
int main()
{
if(!testRead()) return 1;
if(!testPos()) return 1;
if(!testCase()) return 1;
return 0;
}

View file

@ -1,11 +0,0 @@
TEMPLATE = app
CONFIG += qt warn_on console
QT -= gui
DEPENDPATH += .
INCLUDEPATH += . ../../
LIBS += -L../../bin -lquazip
# Input
SOURCES += main.cpp

View file

@ -1 +0,0 @@
*.zip zip

View file

@ -1,2 +0,0 @@
add_executable(zip main.cpp)
target_link_libraries(zip quazip)

View file

@ -1,78 +0,0 @@
#include <QDir>
#include <QFile>
#include <quazip/quazip.h>
#include <quazip/quazipfile.h>
/* A simple test program. Creates "test.zip" using the files in the
* current directory.
*/
// test creating archive
bool testCreate()
{
QFile zipFile("test.zip");
QuaZip zip(&zipFile);
if(!zip.open(QuaZip::mdCreate)) {
qWarning("testCreate(): zip.open(): %d", zip.getZipError());
return false;
}
zip.setComment("Test comment");
QFileInfoList files=QDir().entryInfoList();
QFile inFile;
QuaZipFile outFile(&zip);
char c;
foreach(QFileInfo file, files) {
if(!file.isFile()||file.fileName()=="test.zip") continue;
inFile.setFileName(file.fileName());
if(!inFile.open(QIODevice::ReadOnly)) {
qWarning("testCreate(): inFile.open(): %s", inFile.errorString().toLocal8Bit().constData());
return false;
}
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(inFile.fileName(), inFile.fileName()))) {
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return false;
}
qint64 len = file.size();
qint64 pos = 0;
while (inFile.getChar(&c)&&outFile.putChar(c)) {
char buf[4096];
qint64 l = inFile.read(buf, 4096);
if (l < 0) {
qWarning("read(): %s", inFile.errorString().toUtf8().constData());
break;
}
if (l == 0)
break;
if (outFile.write(buf, l) != l) {
qWarning("write(): %d", outFile.getZipError());
break;
}
pos += l;
if (pos % 1048576 == 0)
qDebug("%.1f", (float) pos / len * 100.0f);
}
if(outFile.getZipError()!=UNZ_OK) {
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return false;
}
outFile.close();
if(outFile.getZipError()!=UNZ_OK) {
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return false;
}
inFile.close();
}
zip.close();
if(zip.getZipError()!=0) {
qWarning("testCreate(): zip.close(): %d", zip.getZipError());
return false;
}
return true;
}
int main()
{
if(!testCreate()) return 1;
return 0;
}

View file

@ -1,11 +0,0 @@
TEMPLATE = app
CONFIG += qt warn_on console
QT -= gui
DEPENDPATH += .
INCLUDEPATH += . ../../
LIBS += -L../../bin -lquazip
# Input
SOURCES += main.cpp