Files
libstrophe-gh/tests/test_string.c
Steffen Jaeckel f49ccb3262 Fix wording of licensing terms
It has been pointed out that the wording of the license of this library is
not entirely clear.

The term "dual licensing" usually refers to a licence choice of two
licenses "LICENSE1 _or_ LICENSE2.
Instead the license of this library claimed "LICENSE1 _and_ LICENSE2".

After an internal discussion with @metajack and @pasis it was made clear
that the initial idea was to dual license the library in the usual way.

This was also made clear by jack on the ML in the past [0].
As of jack, these licensing terms originated from jquery, which also used
the 'and' version in the past and has since been corrected [1].

This patch changes the license terms to 'MIT or GPLv3' and also adds SPDX
headers [2].

[0] https://groups.google.com/g/libstrophe/c/JkFgr601JQc
[1] https://stackoverflow.com/q/2758409
[2] https://spdx.org

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-08-25 18:08:42 +02:00

128 lines
2.7 KiB
C

/* SPDX-License-Identifier: MIT OR GPL-3.0-only */
/* test_string.c
* strophe XMPP client library -- tests for re-implemented string functions
*
* Copyright (C) 2016 Dmitry Podgorny <pasis.ua@gmail.com>
*
* This software is provided AS-IS with no warranty, either express
* or implied.
*
* This program is dual licensed under the MIT or GPLv3 licenses.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "strophe.h"
#include "common.h"
#include "util.h"
#include "test.h" /* ARRAY_SIZE */
/* strtok_s() has appeared in visual studio 2005.
Use own implementation for older versions. */
#ifdef _MSC_VER
#if (_MSC_VER >= 1400)
#define strtok_r strtok_s
#else
#define strtok_r xmpp_strtok_r
#endif
#endif /* _MSC_VER */
static int test_strtok_r(void)
{
const char *test = "-abc-=-def--";
char *s1, *s2, *sub1, *sub2;
char *sp1, *sp2;
s1 = strdup(test);
s2 = strdup(test);
assert(strcmp(s1, s2) == 0);
sub1 = strtok_r(s1, "-", &sp1);
sub2 = strophe_strtok_r(s2, "-", &sp2);
if (strcmp(sub1, sub2) != 0) {
printf("1st token is '%s', must be '%s'\n", sub2, sub1);
return -1;
}
sub1 = strtok_r(NULL, "-=", &sp1);
sub2 = strophe_strtok_r(NULL, "-=", &sp2);
if (strcmp(sub1, sub2) != 0) {
printf("2nd token is '%s', must be '%s'\n", sub2, sub1);
return -1;
}
sub1 = strtok_r(NULL, "-", &sp1);
sub2 = strophe_strtok_r(NULL, "-", &sp2);
if (sub1 != sub2) {
printf("3rd call returns %p instead of NULL\n", sub2);
return -1;
}
free(s1);
free(s2);
return 0;
}
static int test_strdup_one(xmpp_ctx_t *ctx, const char *s)
{
char *s1, *s2;
int rc = 0;
s1 = strdup(s);
s2 = strophe_strdup(ctx, s);
if (!s1 || !s2 || strcmp(s1, s2) != 0) {
rc = -1;
printf("strdup: '%s', xmpp_strdup: '%s'\n", s1 ? s1 : "<NULL>",
s2 ? s2 : "<NULL>");
}
free(s1);
if (s2)
strophe_free(ctx, s2);
return rc;
}
static int test_strdup(void)
{
xmpp_ctx_t *ctx;
size_t i;
int rc = 0;
static const char *tests[] = {"", "\0", "test", "s p a c e", "\n\r"};
ctx = xmpp_ctx_new(NULL, NULL);
assert(ctx != NULL);
for (i = 0; i < ARRAY_SIZE(tests); ++i) {
rc = test_strdup_one(ctx, tests[i]);
if (rc != 0)
break;
}
xmpp_ctx_free(ctx);
return rc;
}
int main()
{
int rc;
printf("xmpp_strtok_r() tests... ");
rc = test_strtok_r();
if (rc != 0)
return 1;
printf("ok\n");
printf("xmpp_strdup() tests... ");
rc = test_strdup();
if (rc != 0)
return 1;
printf("ok\n");
return 0;
}