예제 #1
0
void ChecksumTests::TestCheckFileChecksum() {
    gRepository.SetSettings("sqlite3", "database=:memory:");
    gRepository.Connect();
    gRepository.PopulateDatabase();

    Q_INIT_RESOURCE(server_resources);  // Use resources from diffrent project
    QImage vAddedImage {QImage(":/sample_photo.jpg", "JPG")};

    // Part adding image
    QBuffer vBufferToStoreData;
    QImageWriter vWriter(&vBufferToStoreData, "JPG");
    vWriter.write(vAddedImage);

    QByteArray vAddedData {vBufferToStoreData.data()};

    uint16_t vChecksumAddImage = CalculateChecksumHelper::CalculateFileDataChecksum(
                                     vAddedData);

    CStorePhotoTransaction vStoreTransaction(
        vAddedData, vAddedData.size(), vChecksumAddImage);
    vStoreTransaction.Execute();

    CChecksumList *vChecksumList {gRepository.GetChecksumList()};
    QVERIFY(vChecksumList->CheckFileChecksum(vChecksumAddImage));
}
예제 #2
0
void StorePhotoTests::TestStorePhoto() {
    gRepository.SetSettings("sqlite3",
                            "database=:memory:"); // dzięki temu, że w pamięci testy można w jenkinsie
    gRepository.Connect();
    gRepository.PopulateDatabase();

    Q_INIT_RESOURCE(server_resources);  // Use resources from diffrent project

    QImage vAddedImage {QImage(":/sample_photo.jpg", "JPG")};

    // Part adding image
    QBuffer vBufferToStoreData;

    QImageWriter vWriter(&vBufferToStoreData, "JPG");
    vWriter.write(vAddedImage);

    QByteArray vAddedData = vBufferToStoreData.data();
    int16_t vChecksumAddImage = CalculateFileDataChecksumHelper(vAddedData);

    CStorePhotoTransaction vStoreTransaction(
        vAddedData, vAddedData.size(), vChecksumAddImage);
    vStoreTransaction.Execute();

    CRetrievePhotoTransaction vRetrieveTransaction(vChecksumAddImage);
    vRetrieveTransaction.Execute();

    QByteArray vRetrievedData = vRetrieveTransaction.GetData();

    QCOMPARE(vAddedData, vRetrievedData);

    // Convert array of bytes to image
    QBuffer vBufferRetrieveData(&vRetrievedData);
    vBufferRetrieveData.open(QIODevice::ReadOnly);

    QImageReader vReader(&vBufferRetrieveData, "JPG");
    QImage vRetrievedImage = vReader.read();

    QCOMPARE(vAddedImage.size(), vRetrievedImage.size());
    QCOMPARE(vAddedImage.format(), vRetrievedImage.format());

    int16_t vChecksumRetrievedImage =
        CalculateFileDataChecksumHelper(vRetrievedData);

    QCOMPARE(vChecksumAddImage, vChecksumRetrievedImage);

    // QVERIFY(vImage2.operator==(vImage));  // porównanie qimage  w tym przypadku różne
    // Pixel compare: różne 4281016857 != 4281016597

}
예제 #3
0
void DataMethodsTests::TestServeReceivedFileData() {
    gRepository.SetSettings("sqlite3",
                            "database=:memory:");
    gRepository.Connect();
    gRepository.PopulateDatabase();
    CReceiverWrapper vReceiver;

    QByteArray *vData {new QByteArray("Test data")};

    vReceiver.ForTestSetDataSize(new int32_t(9));
    vReceiver.ForTestSetReceiveBuffer(vData);

    vReceiver.ForTestServeReceivedFileData();
    ///@todo
    CRetrievePhotoTransaction vRetrieveTransaction(858);
    vRetrieveTransaction.Execute();

    QByteArray vRetrievedData = vRetrieveTransaction.GetData();
    QCOMPARE(vRetrievedData, QByteArray("Test data"));
}