/***************************************************************************
 *   Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>  *
 ***************************************************************************/
/** @file
 * This file is a test script.
 *
 * @author Stephane MANKOWSKI / Guillaume DE BURE
 */
#include "skgtestmacro.h"
#include "skgbankincludes.h"

/**
 * The main function of the unit test
 * @param argc the number of arguments
 * @param argv the list of arguments
 */
int main(int argc, char** argv)
{
    Q_UNUSED(argc);
    Q_UNUSED(argv);

    // Init test
    SKGINITTEST(true);

    {
        // Test restore
        SKGDocumentBank document1;
        SKGTESTERROR("document1.initialize()", document1.initialize(), true);
        SKGTESTERROR("document1.load(nopwd.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/nopwd.skg", "", true), true);
        SKGTESTERROR("document1.load(pwd.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/pwd.skg", "", true), false);
        SKGTESTERROR("document1.load(pwd.skg, a)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/pwd.skg", "a", true), true);

        QFile(SKGTest::getTestPath("OUT") % "/skgtestrestore/.nopwd.skg.wrk").remove();
        SKGTESTERROR("document1.load(nopwd.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/nopwd.skg", "", true), true);
    }

    {
        // Test load file
        SKGDocumentBank document1;
        SKGTESTERROR("document1.initialize()", document1.initialize(), true);
        SKGTESTERROR("document1.load(sqlite_no_pwd.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/sqlite_no_pwd.skg", "", true), true);
        SKGTESTERROR("document1.load(sqlite_pwd_ABC.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/sqlite_pwd_ABC.skg", "ABC", true), true);
#ifdef SKGCIPHER
        SKGTESTERROR("document1.load(sqlcipher_no_pwd.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/sqlcipher_no_pwd.skg", "", true), true);
        SKGTESTERROR("document1.load(sqlcipher_pwd_ABC.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/sqlcipher_pwd_ABC.skg", "ABC", true), true);
#else
        SKGTESTERROR("document1.load(sqlcipher_no_pwd.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/sqlcipher_no_pwd.skg", "", true), false);
        SKGTESTERROR("document1.load(sqlcipher_pwd_ABC.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/sqlcipher_pwd_ABC.skg", "ABC", true), false);
#endif
    }

    {
        // Test load (sqlite mode) + save + load
        SKGDocumentBank document1;
        SKGTESTERROR("document1.initialize()", document1.initialize(), true);
        SKGTESTERROR("document1.load(nopwd.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/nopwd.skg", "", true), true);
        SKGTESTERROR("document1.saveas(nopwd2.skg)", document1.saveAs(SKGTest::getTestPath("OUT") % "/skgtestrestore/nopwd2.skg", true), true);
        SKGTESTERROR("document1.load(nopwd2.skg)", document1.load(SKGTest::getTestPath("OUT") % "/skgtestrestore/nopwd2.skg", "", true), true);
    }
    // End test
    SKGENDTEST();
}
