tests: net: zoap: Add path uri matching tests
Test the match_path_uri() function that was fixed by previous commit. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
7bed585c42
commit
3677caa37e
4 changed files with 88 additions and 0 deletions
|
@ -13,6 +13,14 @@ config ZOAP
|
||||||
help
|
help
|
||||||
This option enables the Zoap implementation of CoAP.
|
This option enables the Zoap implementation of CoAP.
|
||||||
|
|
||||||
|
# This setting is only used by unit test. Do not enable it in applications
|
||||||
|
config ZOAP_TEST_API_ENABLE
|
||||||
|
bool "Enable test API for ZoAP unit tests"
|
||||||
|
default n
|
||||||
|
depends on ZOAP
|
||||||
|
help
|
||||||
|
Do not enable this for normal use.
|
||||||
|
|
||||||
config ZOAP_WELL_KNOWN_BLOCK_WISE
|
config ZOAP_WELL_KNOWN_BLOCK_WISE
|
||||||
bool
|
bool
|
||||||
prompt "CoAP ./well-known/core services block wise support"
|
prompt "CoAP ./well-known/core services block wise support"
|
||||||
|
|
|
@ -715,3 +715,12 @@ done:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Exposing some of the APIs to ZoAP unit tests in tests/net/lib/zoap */
|
||||||
|
#if defined(CONFIG_ZOAP_TEST_API_ENABLE)
|
||||||
|
bool _zoap_match_path_uri(const char * const *path,
|
||||||
|
const char *uri, u16_t len)
|
||||||
|
{
|
||||||
|
return match_path_uri(path, uri, len);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -5,3 +5,4 @@ CONFIG_NETWORKING_WITH_IPV6=y
|
||||||
CONFIG_RANDOM_GENERATOR=y
|
CONFIG_RANDOM_GENERATOR=y
|
||||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||||
CONFIG_ZOAP=y
|
CONFIG_ZOAP=y
|
||||||
|
CONFIG_ZOAP_TEST_API_ENABLE=y
|
||||||
|
|
|
@ -39,6 +39,10 @@ static struct zoap_pending pendings[NUM_PENDINGS];
|
||||||
static struct zoap_observer observers[NUM_OBSERVERS];
|
static struct zoap_observer observers[NUM_OBSERVERS];
|
||||||
static struct zoap_reply replies[NUM_REPLIES];
|
static struct zoap_reply replies[NUM_REPLIES];
|
||||||
|
|
||||||
|
/* This is exposed for this test in subsys/net/lib/zoap/zoap_link_format.c */
|
||||||
|
bool _zoap_match_path_uri(const char * const *path,
|
||||||
|
const char *uri, u16_t len);
|
||||||
|
|
||||||
/* Some forward declarations */
|
/* Some forward declarations */
|
||||||
static void server_notify_callback(struct zoap_resource *resource,
|
static void server_notify_callback(struct zoap_resource *resource,
|
||||||
struct zoap_observer *observer);
|
struct zoap_observer *observer);
|
||||||
|
@ -1060,6 +1064,71 @@ done:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_match_path_uri(void)
|
||||||
|
{
|
||||||
|
int result = TC_FAIL;
|
||||||
|
const char * const resource_path[] = {
|
||||||
|
"s",
|
||||||
|
"1",
|
||||||
|
"foobar",
|
||||||
|
"foobar3a",
|
||||||
|
"foobar3",
|
||||||
|
"devnull",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
const char *uri;
|
||||||
|
|
||||||
|
uri = "/k";
|
||||||
|
if (_zoap_match_path_uri(resource_path, uri, strlen(uri))) {
|
||||||
|
TC_PRINT("Matching %s failed\n", uri);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri = "/s";
|
||||||
|
if (!_zoap_match_path_uri(resource_path, uri, strlen(uri))) {
|
||||||
|
TC_PRINT("Matching %s failed\n", uri);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri = "/foobar";
|
||||||
|
if (!_zoap_match_path_uri(resource_path, uri, strlen(uri))) {
|
||||||
|
TC_PRINT("Matching %s failed\n", uri);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri = "/foobar2";
|
||||||
|
if (_zoap_match_path_uri(resource_path, uri, strlen(uri))) {
|
||||||
|
TC_PRINT("Matching %s failed\n", uri);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri = "/foobar*";
|
||||||
|
if (!_zoap_match_path_uri(resource_path, uri, strlen(uri))) {
|
||||||
|
TC_PRINT("Matching %s failed\n", uri);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri = "/foobar3*";
|
||||||
|
if (!_zoap_match_path_uri(resource_path, uri, strlen(uri))) {
|
||||||
|
TC_PRINT("Matching %s failed\n", uri);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri = "/devnull*";
|
||||||
|
if (_zoap_match_path_uri(resource_path, uri, strlen(uri))) {
|
||||||
|
TC_PRINT("Matching %s failed\n", uri);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = TC_PASS;
|
||||||
|
|
||||||
|
out:
|
||||||
|
TC_END_RESULT(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*func)(void);
|
int (*func)(void);
|
||||||
|
@ -1073,6 +1142,7 @@ static const struct {
|
||||||
{ "Test observer server", test_observer_server, },
|
{ "Test observer server", test_observer_server, },
|
||||||
{ "Test observer client", test_observer_client, },
|
{ "Test observer client", test_observer_client, },
|
||||||
{ "Test block sized transfer", test_block_size, },
|
{ "Test block sized transfer", test_block_size, },
|
||||||
|
{ "Test match path uri", test_match_path_uri, },
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue