]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/cats_test.c
Change copyright as per agreement with FSFE + update copyright year
[bacula/bacula] / bacula / src / tools / cats_test.c
index 50ddb1a58600f9535d34c457f4a0840bf9e9e8a6..75adc4d303a0d0e486f1df9e6bc657a9540369fa 100644 (file)
@@ -1,37 +1,27 @@
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
-
-   The main author of Bacula is Kern Sibbald, with contributions from
-   many others, a complete list can be found in the file AUTHORS.
-   This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version three of the GNU Affero General Public
-   License as published by the Free Software Foundation and included
-   in the file LICENSE.
-
-   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 Affero General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-   Bacula® is a registered trademark of Kern Sibbald.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
-   Switzerland, email:ftf@fsfeurope.org.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2016 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 /*
  *  Program to test CATS DB routines
  *
  *  
  */
-#define __SQL_C
-#define BUILDING_CATS
+#define _BDB_PRIV_INTERFACE_
 
 #include "bacula.h"
 #include "cats/cats.h"
@@ -39,7 +29,7 @@
 #include "findlib/find.h"
  
 /* Local variables */
-static B_DB *db;
+static BDB *db;
 static const char *file = "COPYRIGHT";
 //static DBId_t fnid=0;
 static const char *db_name = "bacula";
@@ -56,7 +46,7 @@ static void usage()
 {
    fprintf(stderr, _(
 PROG_COPYRIGHT
-"\nVersion: %s (%s)\n"
+"\n%sVersion: %s (%s)\n"
 "       -d <nn>           set debug level to <nn>\n"
 "       -dt               print timestamp in debug output\n"
 "       -n <name>         specify the database name (default bacula)\n"
@@ -69,7 +59,7 @@ PROG_COPYRIGHT
 "       -l <limit>        maximum tuple to fetch\n"
 "       -q                print only errors\n"
 "       -v                verbose\n"
-"       -?                print this message\n\n"), 2011, VERSION, BDATE);
+"       -?                print this message\n\n"), 2011, BDEMO, VERSION, BDATE);
    exit(1);
 }
 
@@ -138,23 +128,23 @@ int report()
 
 static void cmp_pool(POOL_DBR &pr, POOL_DBR &pr2)
 {
-   ok(pr.MaxVols == pr2.MaxVols,      "  Check Pool MaxVols");
-   ok(pr.UseOnce == pr2.UseOnce,      "  Check Pool UseOnce");
-   ok(pr.UseCatalog == pr2.UseCatalog,"  Check Pool UseCatalog");
+   ok(pr.MaxVols == pr2.MaxVols,                "  Check Pool MaxVols");
+   ok(pr.UseOnce == pr2.UseOnce,                "  Check Pool UseOnce");
+   ok(pr.UseCatalog == pr2.UseCatalog,          "  Check Pool UseCatalog");
    ok(pr.AcceptAnyVolume == pr2.AcceptAnyVolume,"  Check Pool AcceptAnyVolume");
-   ok(pr.AutoPrune == pr2.AutoPrune,   "  Check Pool AutoPrune");
-   ok(pr.Recycle == pr2.Recycle,       "  Check Pool Recycle");
-   ok(pr.VolRetention == pr2.VolRetention,    "  Check Pool VolRetention");
-   ok(pr.VolUseDuration == pr2.VolUseDuration,"  Check Pool VolUseDuration");
-   ok(pr.MaxVolJobs == pr2.MaxVolJobs,     "  Check Pool MaxVolJobs");
-   ok(pr.MaxVolFiles == pr2.MaxVolFiles,   "  Check Pool MaxVolFiles");
-   ok(pr.MaxVolBytes == pr2.MaxVolBytes,   "  Check Pool MaxVolBytes");
-   ok(!strcmp(pr.PoolType, pr2.PoolType),  "  Check Pool PoolType");
-   ok(pr.LabelType == pr2.LabelType,       "  Check Pool LabelType");
-   ok(!strcmp(pr.LabelFormat, pr2.LabelFormat),   "  Check Pool LabelFormat");
-   ok(pr.RecyclePoolId == pr2.RecyclePoolId,   "  Check Pool RecyclePoolId");
-   ok(pr.ScratchPoolId == pr2.ScratchPoolId,   "  Check Pool ScratchPoolId");
-   ok(pr.ActionOnPurge == pr2.ActionOnPurge,   "  Check Pool ActionOnPurge");
+   ok(pr.AutoPrune == pr2.AutoPrune,            "  Check Pool AutoPrune");
+   ok(pr.Recycle == pr2.Recycle,                "  Check Pool Recycle");
+   ok(pr.VolRetention == pr2.VolRetention ,     "  Check Pool VolRetention");
+   ok(pr.VolUseDuration == pr2.VolUseDuration,  "  Check Pool VolUseDuration");
+   ok(pr.MaxVolJobs == pr2.MaxVolJobs,          "  Check Pool MaxVolJobs");
+   ok(pr.MaxVolFiles == pr2.MaxVolFiles,        "  Check Pool MaxVolFiles");
+   ok(pr.MaxVolBytes == pr2.MaxVolBytes,        "  Check Pool MaxVolBytes");
+   ok(!strcmp(pr.PoolType, pr2.PoolType),       "  Check Pool PoolType");
+   ok(pr.LabelType == pr2.LabelType,            "  Check Pool LabelType");
+   ok(!strcmp(pr.LabelFormat, pr2.LabelFormat), "  Check Pool LabelFormat");
+   ok(pr.RecyclePoolId == pr2.RecyclePoolId,    "  Check Pool RecyclePoolId");
+   ok(pr.ScratchPoolId == pr2.ScratchPoolId,    "  Check Pool ScratchPoolId");
+   ok(pr.ActionOnPurge == pr2.ActionOnPurge,    "  Check Pool ActionOnPurge");
 }
 
 static void cmp_client(CLIENT_DBR &cr, CLIENT_DBR &cr2)
@@ -166,13 +156,42 @@ static void cmp_client(CLIENT_DBR &cr, CLIENT_DBR &cr2)
    ok(cr.FileRetention == cr2.FileRetention,"  Check Client FileRetention");
 }
 
+static void cmp_job(JOB_DBR &jr, JOB_DBR &jr2)
+{
+   ok(jr.VolSessionId == jr2.VolSessionId,     "  Check VolSessionId");
+   ok(jr.VolSessionTime == jr2.VolSessionTime, "  Check VolSessionTime");
+   ok(jr.PoolId == jr2.PoolId,                 "  Check PoolId");
+   ok(jr.StartTime == jr2.StartTime,           "  Check StartTime");
+   ok(jr.EndTime == jr2.EndTime,               "  Check EndTime");
+   ok(jr.JobFiles == jr2.JobFiles,             "  Check JobFiles");
+   ok(jr.JobBytes == jr2.JobBytes,             "  Check JobBytes");
+   ok(jr.JobTDate == jr2.JobTDate,             "  Check JobTDate");
+   ok(!strcmp(jr.Job, jr2.Job),                "  Check Job");
+   ok(jr.JobStatus == jr2.JobStatus,           "  Check JobStatus");
+   ok(jr.JobType == jr2.JobType,               "  Check Type");
+   ok(jr.JobLevel == jr2.JobLevel,             "  Check Level");
+   ok(jr.ClientId == jr2.ClientId,             "  Check ClientId");
+   ok(!strcmp(jr.Name, jr2.Name),              "  Check Name");
+   ok(jr.PriorJobId == jr2.PriorJobId,         "  Check PriorJobId");
+   ok(jr.RealEndTime == jr2.RealEndTime,       "  Check RealEndTime");
+   ok(jr.JobId == jr2.JobId,                   "  Check JobId");
+   ok(jr.FileSetId == jr2.FileSetId,           "  Check FileSetId");
+   ok(jr.SchedTime == jr2.SchedTime,           "  Check SchedTime");
+   ok(jr.RealEndTime == jr2.RealEndTime,       "  Check RealEndTime");
+   ok(jr.ReadBytes == jr2.ReadBytes,           "  Check ReadBytes");
+   ok(jr.HasBase == jr2.HasBase,               "  Check HasBase");
+   ok(jr.PurgedFiles == jr2.PurgedFiles,       "  Check PurgedFiles");
+}
+
+
 #define aPATH "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 #define aFILE "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 
-int list_files(void *ctx, int nb_col, char **row)
+static int list_files(void *ctx, int nb_col, char **row)
 {
    uint32_t *k = (uint32_t*) ctx;
    (*k)++;
+   ok(nb_col > 4, "Check result columns");
    ok(!strcmp(row[0], aPATH aPATH aPATH aPATH "/"), "Check path");
    ok(!strcmp(row[1], aFILE aFILE ".txt"), "Check filename");
    ok(str_to_int64(row[2]) == 10, "Check FileIndex");
@@ -180,6 +199,12 @@ int list_files(void *ctx, int nb_col, char **row)
    return 1;
 }
 
+static int count_col(void *ctx, int nb_col, char **row)
+{
+   *((int32_t*) ctx) = nb_col;
+   return 1;
+}
+
 /* number of thread started */
 
 int main (int argc, char *argv[])
@@ -299,8 +324,8 @@ int main (int argc, char *argv[])
     */
 
    jcr = new_jcr(sizeof(JCR), NULL);
-   jcr->set_JobType(JT_CONSOLE);
-   jcr->set_JobLevel(L_NONE);
+   jcr->setJobType(JT_CONSOLE); 
+   jcr->setJobLevel(L_NONE); 
    jcr->JobStatus = JS_Running;
    bstrncpy(jcr->Job, "**dummy**", sizeof(jcr->Job));
    jcr->JobId = pid;      /* this is JobId on tape */
@@ -310,11 +335,13 @@ int main (int argc, char *argv[])
    Pmsg1(0, PLINE "Test DB connection \"%s\"" PLINE, db_name);
 
    if (full_test) {
-      db = db_init(jcr /* JCR */, 
+      db = db_init_database(jcr /* JCR */, 
                    NULL /* dbi driver */,
                    db_name, db_user, db_password, db_address, db_port + 100,
                    NULL /* db_socket */,
-                   0 /* mult_db_connections */);
+                   db_ssl_key, db_ssl_cert, db_ssl_ca,
+                   db_ssl_capath, db_ssl_cipher,
+                   0 /* mult_db_connections */, false);
       ok(db != NULL, "Test bad connection");
       if (!db) {
          report();
@@ -324,11 +351,13 @@ int main (int argc, char *argv[])
       db_close_database(jcr, db);
    }
 
-   db = db_init(jcr /* JCR */, 
+   db = db_init_database(jcr /* JCR */, 
                 NULL /* dbi driver */,
                 db_name, db_user, db_password, db_address, db_port,
                 NULL /* db_socket */,
-                0 /* mult_db_connections */);
+                db_ssl_key, db_ssl_cert, db_ssl_ca,
+                db_ssl_capath, db_ssl_cipher,
+                false /* mult_db_connections */, false);
 
    ok(db != NULL, "Test db connection");
    if (!db) {
@@ -344,10 +373,10 @@ int main (int argc, char *argv[])
       report();
       exit (1);
    }
-   dbtype = db_type;
+   dbtype = db_get_type_index(db);
+
 
    /* Check if the SQL library is thread-safe */
-   db_check_backend_thread_safe();
    ok(check_tables_version(jcr, db), "Check table version");
    ok(db_sql_query(db, "SELECT VersionId FROM Version", 
                    db_int_handler, &j), "SELECT VersionId");
@@ -380,6 +409,11 @@ int main (int argc, char *argv[])
 
    /* ---------------------------------------------------------------- */
    Pmsg0(0, PLINE "Doing Basic SQL tests" PLINE);
+   ok(db_sql_query(db, "SELECT 1,2,3,4,5", count_col, &j), "Count 5 rows");
+   ok(j == 5, "Check number of columns");
+   ok(db_sql_query(db, "SELECT 1,2,3,4,5,'a','b','c','d','e'", 
+                   count_col, &j), "Count 10 rows");
+   ok(j == 10, "Check number of columns");
 
    bsnprintf(temp, sizeof(temp), "t%lld", pid);
    ok(db_sql_query(db, "SELECT 2", db_int_handler, &j), "Good SELECT query");
@@ -441,6 +475,7 @@ int main (int argc, char *argv[])
    ok(db_sql_query(db, buf, NULL, NULL), "Inserting quoted string");
 
    /* ---------------------------------------------------------------- */
+   Pmsg0(0, PLINE "Doing Job tests" PLINE);   
 
    JOB_DBR jr, jr2;
    memset(&jr, 0, sizeof(jr));
@@ -453,9 +488,26 @@ int main (int argc, char *argv[])
    Mmsg(buf, "%s-%lld", jr.Job, pid);
    strcpy(jr.Job, buf);
    ok(db_create_job_record(jcr, db, &jr), "Create Job record");
+   ok(db_update_job_start_record(jcr, db, &jr), "Update Start Record");
+   ok(db_update_job_end_record(jcr, db, &jr), "Update End Record");
+   jr2.JobId = jr.JobId;
+   ok(db_get_job_record(jcr, db, &jr2), "Get Job record by JobId");
+   cmp_job(jr, jr2);
+
+   memset(&jr2, 0, sizeof(jr2));
+   strcpy(jr2.Job, jr.Job);
+   ok(db_get_job_record(jcr, db, &jr2), "Get Job record by Job name");
+   cmp_job(jr, jr2);
+
+   memset(&jr2, 0, sizeof(jr2));
+   jr2.JobId = 99999;
+   nok(db_get_job_record(jcr, db, &jr2), "Get non existing Job record (JobId)");
+
+   memset(&jr2, 0, sizeof(jr2));
+   strcpy(jr2.Job, "test");
+   nok(db_get_job_record(jcr, db, &jr2), "Get non existing Job record (Job)");
 
    /* ---------------------------------------------------------------- */
-   
 
    ATTR_DBR ar;
    memset(&ar, 0, sizeof(ar));
@@ -468,7 +520,7 @@ int main (int argc, char *argv[])
    ar.FileType = FT_REG;
    jcr->JobId = ar.JobId = jr.JobId;
    jcr->JobStatus = JS_Running;
-   ok(db_create_file_attributes_record(jcr, db, &ar), "Inserting Filename");
+   ok(db_create_attributes_record(jcr, db, &ar), "Inserting Filename");
    ok(db_write_batch_file_records(jcr), "Commit batch session");
    Mmsg(buf, "SELECT FileIndex FROM File WHERE JobId=%lld",(int64_t)jcr->JobId);
    ok(db_sql_query(db, buf, db_int_handler, &j), "Get Inserted record");
@@ -571,7 +623,7 @@ int main (int argc, char *argv[])
 
    Pmsg0(0, "Search pool by PoolId\n");
    nok(db_create_pool_record(jcr, db, &pr),"Can't create pool twice");
-   ok(db_get_pool_record(jcr, db, &pr2), "Search pool by PoolId");
+   ok(db_get_pool_numvols(jcr, db, &pr2), "Search pool by PoolId");
    cmp_pool(pr, pr2);
 
    pr2.MaxVols++;
@@ -591,7 +643,7 @@ int main (int argc, char *argv[])
    ok(db_update_pool_record(jcr, db, &pr2), "Update Pool record");
    memset(&pr, 0, sizeof(pr));
    pr.PoolId = pr2.PoolId;
-   ok(db_get_pool_record(jcr, db, &pr), "Search pool by PoolId");
+   ok(db_get_pool_numvols(jcr, db, &pr), "Search pool by PoolId");
    cmp_pool(pr, pr2);
 
    ok(db_delete_pool_record(jcr, db, &pr), "Delete Pool");
@@ -638,9 +690,6 @@ int main (int argc, char *argv[])
    ok(db_create_media_record(jcr, db, &mr), "Create Media");
    nok(db_create_media_record(jcr, db, &mr), "Create Media twice");
 
-   /* ---------------------------------------------------------------- */
-   Pmsg0(0, PLINE "Doing Job tests" PLINE);
-   
    /* ---------------------------------------------------------------- */
    Pmsg0(0, PLINE "Doing ... tests" PLINE);