1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
#define CATCH_CONFIG_MAIN
#ifdef CATCH2_MAJOR_VERSION_2
#include <catch2/catch.hpp>
#elif CATCH2_MAJOR_VERSION_3
#include <catch2/catch_all.hpp>
#endif
#include <QDebug>
#include <iostream>
#include <odsstream/odsexception.h>
#include <odsstream/tsvdirectorywriter.h>
#include <odsstream/tsvoutputstream.h>
#include <odsstream/writer/options/odscolorscale.h>
#include <odsstream/tsvreader.h>
#include <odsstream/ziptsvoutputstream.h>
#include "config.h"
using namespace std;
// make test ARGS="-V -I 2,2"
//./test/test_tsv [TSVZIP] -s
class CustomHandler : public OdsDocHandlerInterface
{
public:
/**
* callback that indicates the begining of a data sheet. Override it in
* order to retrieve information about the current data sheet.
*
*/
virtual void startSheet([[maybe_unused]] const QString &sheet_name){};
/**
* callback that indicates the end of the current data sheet. Override it if
* needed
*/
virtual void
endSheet()
{
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " endSheet";
};
/**
* callback that indicates a new line start. Override it if needed.
*/
virtual void
startLine()
{
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " startLine";
};
/**
* callback that indicates a line ending. Override it if needed.
*/
virtual void
endLine()
{
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " endLine";
};
/**
* callback that report the content of the current cell in a dedicated Cell
* object. Override it if you need to retrieve cell content.
*/
virtual void
setCell(const OdsCell &cell) override
{
qDebug() << cell.toString();
};
/**
* callback that report the end of the ODS document. Override it if you need
* to know that reading is finished.
*/
virtual void endDocument(){};
};
TEST_CASE("TSV test suite.", "[TSV]")
{
// Set the debugging message formatting pattern.
qSetMessagePattern(QString("%{file}@%{line}, %{function}(): %{message}"));
// QCoreApplication a(argc, argv);
SECTION("..:: Test TsvDirectoryWriter ::..", "[TSV]")
{
TsvDirectoryWriter writer(QDir("test"));
writer.setFlushLines(true);
QString test("truc");
writer.writeSheet("classeur");
writer.setCellAnnotation("test annot");
writer.writeCell(test);
writer.writeLine();
writer.writeEmptyCell();
writer.writeCell("coucou\" ceci est un quote");
bool vf(0);
writer.writeCell(vf);
writer.writeCellPercentage(0.23565654545);
writer.clearTableCellStyleRef();
writer.writeLine();
writer.writeLine();
writer.writeLine();
writer.writeCell(1);
QString start_position = writer.getOdsCellCoordinate();
writer.writeCell(2);
writer.writeCell(3);
writer.writeCell(4);
writer.writeCell(5);
writer.writeLine();
writer.writeCell(6);
writer.writeCell(7);
writer.writeCell(8);
writer.writeCell(9);
writer.writeCell(10);
QString end_position = writer.getOdsCellCoordinate();
OdsColorScale color_scale(start_position, end_position);
writer.addColorScale(color_scale);
writer.writeSheet("classeur2");
writer.setCellAnnotation("test annot");
writer.writeCell(test);
writer.writeLine();
writer.writeEmptyCell();
writer.writeCell("coucou");
QDateTime currentdate(QDateTime::currentDateTime());
writer.writeCell(currentdate);
writer.close();
QTextStream terminalOut(stdout, QIODevice::WriteOnly);
TsvOutputStream writero(terminalOut);
writero.setFlushLines(true);
writero.writeSheet("classeur");
writero.writeCell(test);
writero.writeLine();
writero.writeEmptyCell();
writero.setCellAnnotation("ne sera pas prise en compte en TSV");
writero.writeCell("coucou");
writero.writeCell(vf);
writero.writeCell(currentdate);
writero.close();
CustomHandler handler;
TsvReader tsv_reader(handler);
// tsv_reader.setSeparator(TsvSeparator::comma);
QFile tsv_file("test/classeur.tsv");
tsv_reader.parse(tsv_file);
}
}
TEST_CASE("TSV ZIP test suite.", "[TSVZIP]")
{
// Set the debugging message formatting pattern.
qSetMessagePattern(QString("%{file}@%{line}, %{function}(): %{message}"));
INFO("begin");
ZipTsvOutputStream writer("test.zip");
INFO("coucou");
writer.setFlushLines(true);
QString test("truc");
INFO("coucou2");
writer.writeSheet("classeur");
writer.setCellAnnotation("test annot");
writer.writeCell(test);
writer.writeLine();
writer.writeEmptyCell();
writer.writeCell("coucou\" ceci est un quote");
bool vf(0);
writer.writeCell(vf);
writer.writeCellPercentage(0.23565654545);
writer.clearTableCellStyleRef();
writer.writeLine();
writer.writeLine();
writer.writeLine();
writer.writeCell(1);
QString start_position = writer.getOdsCellCoordinate();
writer.writeCell(2);
writer.writeCell(3);
writer.writeCell(4);
writer.writeCell(5);
writer.writeLine();
writer.writeCell(6);
writer.writeCell(7);
writer.writeCell(8);
writer.writeCell(9);
writer.writeCell(10);
QString end_position = writer.getOdsCellCoordinate();
OdsColorScale color_scale(start_position, end_position);
writer.addColorScale(color_scale);
writer.writeSheet("classeur2");
writer.setCellAnnotation("test annot");
writer.writeCell(test);
writer.writeLine();
writer.writeEmptyCell();
writer.writeCell("coucou");
QDateTime currentdate(QDateTime::currentDateTime());
writer.writeCell(currentdate);
writer.close();
}
|