コード例 #1
0
ファイル: test.cpp プロジェクト: allan-simon/cppcms-skeleton
int main() {

    bool nothingFailed = true;
    TestModel model;

    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to create the tables ... " ,
        model.import_sql_file(
            SQL_PATH TEST_PATH BASIC_SQL
        ),
        nothingFailed
    );


    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to check the existence of an existing record ... " ,
        model.test(),
        nothingFailed
    );

    CPPCMSSKEL_TEST_RESULT_NOT_WORK(
        "Try to check the existence of a non-existing record ... " ,
        model.test_not_work(),
        nothingFailed
    );


    if (nothingFailed) {
        return 0;
    } else {
        return 1;
    }
}
コード例 #2
0
ファイル: test.cpp プロジェクト: Tatoeba/cppcms-skeleton
int main() {

    bool nothingFailed = true;
    Test model;

    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to create the tables ... " ,
        model.import_sql_file(
          SQL_PATH TEST_PATH BASIC_SQL
        ),
        nothingFailed
    );


    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to check if we can retrieve whole user by its id ... " ,
        model.test_work(),
        nothingFailed
    );

    CPPCMSSKEL_TEST_RESULT_NOT_WORK(
        "Try to check if retreiving a user with a non existing id give a non existing user ... " ,
        model.test_not_work(),
        nothingFailed
    );


    if (nothingFailed) {
        return 0;
    } else {
        return 1;
    }
}
コード例 #3
0
ファイル: test.cpp プロジェクト: Tatoeba/cppcms-skeleton
int main() {

    bool nothingFailed = true;
    Test model;

    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to create the tables ... " ,
        model.import_sql_file(
          SQL_PATH TEST_PATH BASIC_SQL
        ),
        nothingFailed
    );


    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to check if we know that the admin is admin ... " ,
        model.test_work(),
        nothingFailed
    );

    CPPCMSSKEL_TEST_RESULT_NOT_WORK(
        "Try to check if we know an normal user is not admin ... " ,
        model.test_not_work(),
        nothingFailed
    );


    if (nothingFailed) {
        return 0;
    } else {
        return 1;
    }
}
コード例 #4
0
int main() {


    bool noTestFailed = true;
    models::Articles articlesModels(CPPCMSSKEL_TEST_NAME ".db");

    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try load the database ... " ,
        articlesModels.import_sql_file(DB_SQL_FILE_PATH),
        noTestFailed
    );
    
    // we first load some raw articles on the database
    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to load the database with some data ... " ,
        articlesModels.import_sql_file(SQL_FILL_ARTICLES),
        noTestFailed
    );


    
    // we should be able to get an article ...

    std::cout << "Try to get an article ... " ;

    results::Article article = articlesModels.get_from_lang_and_slug(
        TEST_ARTICLE_LANG,
        TEST_ARTICLE_SLUG
    );

    if (article.id > 0 ) {
        std::cout << " [ok]" << std::endl;
    } else {
        std::cout << " [fail]" << std::endl;
        noTestFailed = false;
    }

    // if we request directly the group id of that article, that should be the same
    // value as when we request the entire articel
    std::cout << "We should get the same group id when requesting it directly ... " ;

    int groupId = articlesModels.get_group_id_from_lang_and_slug(
        TEST_ARTICLE_LANG,
        TEST_ARTICLE_SLUG
    );
    if (article.groupId == groupId) {
        std::cout << " [ok]" << std::endl;
    } else {
        std::cout << " [fail]" << std::endl;
        noTestFailed = false;
    }

    if (noTestFailed) {
        return 0;
    } else {
        return 1;
    }

}
コード例 #5
0
ファイル: test.cpp プロジェクト: Tatoeba/cppcms-skeleton
int main() {

    bool nothingFailed = true;
    Test model;

    std::cout << SQL_PATH TEST_PATH BASIC_SQL << std::endl;
    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to create the tables ... " ,
        model.import_sql_file(
          SQL_PATH TEST_PATH BASIC_SQL
        ),
        nothingFailed
    );


    CPPCMSSKEL_TEST_RESULT_WORK(
        "if username AND password are correct => true ... " ,
        model.test_both_ok(),
        nothingFailed
    );

    CPPCMSSKEL_TEST_RESULT_NOT_WORK(
        "If both are not correct => false ... " ,
        model.test_both_wrong(),
        nothingFailed
    );

    CPPCMSSKEL_TEST_RESULT_NOT_WORK(
        "If only username is correct => false ... " ,
        model.test_only_username_ok(),
        nothingFailed
    );

    CPPCMSSKEL_TEST_RESULT_NOT_WORK(
        "If only password is correct => false ... " ,
        model.test_only_password_ok(),
        nothingFailed
    );






    if (nothingFailed) {
        return 0;
    } else {
        return 1;
    }
}
コード例 #6
0
int main() {

    // the goal here is to test the following case
    // 
    // 
    //  a create trigger block contains several ";" but must be imported as
    //  one block, otherwise it will generate an error
    //  so we test that it's possible to import create trigger blocks without
    //  problem

    bool nothingFailed = true;

    cppcmsskel::models::SqliteModel model(TEST_NAME ".db");

    // we first create the database
    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to create the tables ... " ,
        model.import_sql_file(
          SQL_PATH TEST_PATH SQL_NAME
        ),
        nothingFailed
    );


    if (nothingFailed) {
        return 0;
    } else {
        return 1;
    }
}
コード例 #7
0
ファイル: get_from_id.cpp プロジェクト: qdii/tatowiki
int main() {


    bool noTestFailed = true;
    models::Articles articlesModels(TEST_NAME ".db");

    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try load the database ... " ,
        articlesModels.import_sql_file(DB_SQL_FILE_PATH),
        noTestFailed
    );
    
    // we first load some raw articles on the database
    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try to load the database with some data ... " ,
        articlesModels.import_sql_file(SQL_FILL_ARTICLES),
        noTestFailed
    );
    
    // load them again should not work as it will not met
    // the unique(lang,slug) constraint 
    CPPCMSSKEL_TEST_RESULT_NOT_WORK(
        "Load them again should not work ... " ,
        articlesModels.import_sql_file(SQL_FILL_ARTICLES),
        noTestFailed
    );
 
    
    // now we check if we can retrieve an article
    std::cout << "We try to get an article using get_from_lang_slug  ... ";
    results::Article firstArticle = articlesModels.get_from_lang_and_slug(
        "fr",
        "page_principale"
    );
    if ((!firstArticle.exists())) {
        noTestFailed = false;
        std::cout << " [fail]" << std::endl; 
    } else {
        std::cout << " [ok]" << std::endl; 
    }
    // now if we try to get an article with the id of the previous one
    // we should get (of course) the same one
    std::cout << "Using get_from_id to retrieve the same article ... ";
    results::Article secondArticle = articlesModels.get_from_id(
        firstArticle.id
    );
    if (
       !secondArticle.exists() ||
       secondArticle.id != firstArticle.id ||
       secondArticle.slug.compare(firstArticle.slug) != 0 ||
       secondArticle.lang.compare(firstArticle.lang) != 0
    ) {
        noTestFailed = false;
        std::cout << " [fail]" << std::endl; 
    } else {
        std::cout << " [ok]" << std::endl; 
    }

    
    if (noTestFailed) {
        return 0;
    } else {
        return 1;
    }


}
コード例 #8
0
int main() {


    bool noTestFailed = true;
    models::Articles articlesModels(TEST_NAME ".db");

    CPPCMSSKEL_TEST_RESULT_WORK(
        "Try load the database ... " ,
        articlesModels.import_sql_file(DB_SQL_FILE_PATH),
        noTestFailed
    );

    // we should be able to add an article ...

    std::cout << "Try to add an article ... " ;

    int result = articlesModels.create_from_lang_and_slug(
                     TEST_ARTICLE_LANG,
                     TEST_ARTICLE_SLUG,
                     TEST_ARTICLE_TITLE,
                     TEST_ARTICLE_CONTENT
                 );
    if (result == TEST_ARTICLE_ID) {
        std::cout << " [ok]" << std::endl;
    } else {
        std::cout << " [fail]" << std::endl;
        noTestFailed = false;
    }

    // try to add the same article should fail

    std::cout << "Adding the same article twice should be forbidden ... " ;

    result = articlesModels.create_from_lang_and_slug(
                 TEST_ARTICLE_LANG,
                 TEST_ARTICLE_SLUG,
                 TEST_ARTICLE_TITLE,
                 TEST_ARTICLE_CONTENT
             );
    if (result == ARTICLE_CREATION_ERROR) {
        std::cout << " [ok]" << std::endl;
    } else {
        std::cout << " [fail]" << std::endl;
        noTestFailed = false;
    }

    // try to retrieve the article we have added


    // now we check if we can retrieve them

    std::cout << "We now test if we can get it back ... ";
    results::Article firstArticle = articlesModels.get_from_lang_and_slug(
                                        TEST_ARTICLE_LANG,
                                        TEST_ARTICLE_SLUG
                                    );
    if (
        (firstArticle.id != TEST_ARTICLE_ID) ||
        (firstArticle.lang.compare(TEST_ARTICLE_LANG) != 0) ||
        (firstArticle.slug.compare(TEST_ARTICLE_SLUG) != 0) ||
        (firstArticle.title.compare(TEST_ARTICLE_TITLE) != 0) ||
        (firstArticle.content.compare(TEST_ARTICLE_CONTENT) != 0)
    ) {
        noTestFailed = false;
        std::cout << " [fail]" << std::endl;

    } else {
        std::cout << " [ok]" << std::endl;
    }

    //now we try to edit the article
    std::cout << "We now test if we can edit it ... ";
    bool requestSuccess = articlesModels.edit_from_lang_and_slug(
                              TEST_ARTICLE_LANG,
                              TEST_ARTICLE_SLUG,
                              TEST_ARTICLE_NEW_TITLE,
                              TEST_ARTICLE_NEW_CONTENT
                          );

    if(!requestSuccess) {
        noTestFailed = false;
        std::cout << " [fail]" << std::endl;

    } else {
        std::cout << " [ok]" << std::endl;
    }


    // if we try to get back the article, we shoud get the edited version
    std::cout << "The article should have been modfied ... ";
    results::Article editedArticle = articlesModels.get_from_lang_and_slug(
                                         TEST_ARTICLE_LANG,
                                         TEST_ARTICLE_SLUG
                                     );

    if(
        editedArticle.id != TEST_ARTICLE_ID ||
        editedArticle.content.compare(TEST_ARTICLE_NEW_CONTENT) != 0 ||
        editedArticle.title.compare(TEST_ARTICLE_NEW_TITLE) != 0
    ) {
        noTestFailed = false;
        std::cout << " [fail]" << std::endl;

    } else {
        std::cout << " [ok]" << std::endl;
    }





    if (noTestFailed) {
        return 0;
    } else {
        return 1;
    }



}