Skip to content

Commit

Permalink
Merge pull request #3566 from NormB/db_test
Browse files Browse the repository at this point in the history
Add db/test
  • Loading branch information
liviuchircu authored Jan 27, 2025
2 parents a40fad5 + 27a66c4 commit 6ab619c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
51 changes: 51 additions & 0 deletions db/test/test_db.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2018-2021 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips 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
*
* opensips 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
*/

#include <tap.h>

#include "../../str.h"
#include "../../db/db_id.h"
#include "../../lib/osips_malloc.h"
#include "../../sr_module.h"
#include "../../modparam.h"

static void test_db_url(void);

void test_db(void)
{
test_db_url();
}

static void test_db_url(void)
{
#define DB_PARSE(__url) db = new_db_id(_str(__url)); if (!ok(db != NULL)) return;
struct db_id *db;
int i = 1;

DB_PARSE("mysql://user:pass@host:6033/database?parameters");
ok(!strcmp(db->scheme, "mysql"), "parse_db_url: %d-schema: '%s'", i, db->scheme);
ok(!strcmp(db->username, "user"), "parse_db_url: %d-username: '%s'", i, db->username);
ok(!strcmp(db->password, "pass"), "parse_db_url: %d-password: '%s'", i, db->password);
ok(!strcmp(db->host, "host"), "parse_db_url: %d-host: '%s'", i, db->host);
ok((db->port == 6033), "parse_db_url: %d-port: '%d'", i, db->port);
ok((db->unix_socket == NULL), "parse_db_url: %d-unix_socket: '%s'", i, db->unix_socket);
ok(!strcmp(db->database, "database"), "parse_db_url: %d-database: '%s'", i, db->database);
ok(!strcmp(db->parameters, "parameters"), "parse_db_url: %d-parameters: '%s'", i, db->parameters);
}
28 changes: 28 additions & 0 deletions db/test/test_db.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2018-2021 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips 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
*
* opensips 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
*/

#ifndef __TEST_DB_H__
#define __TEST_DB_H__

/* test initialization & execution */
//void init_db_tests(void);
void test_db(void);

#endif /* __TEST_DB_H__ */
2 changes: 2 additions & 0 deletions test/unit_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <tap.h>

#include "../db/test/test_db.h"
#include "../cachedb/test/test_cachedb.h"
#include "../lib/test/test_csv.h"
#include "../lib/test/test_digest_auth.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ int run_unit_tests(void)
test_parser();
test_ut();
test_lib_digest_auth();
test_db();

/* module tests */
} else {
Expand Down

0 comments on commit 6ab619c

Please sign in to comment.