/* Copyright 2011-2020 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #undef NDEBUG #include "serd/serd.h" #include #include #define NS_EG "http://example.org/" static void test_copy(void) { assert(!serd_statement_copy(NULL)); SerdNodes* const nodes = serd_nodes_new(); const SerdNode* const f = serd_nodes_string(nodes, SERD_STRING("file")); const SerdNode* const s = serd_nodes_uri(nodes, SERD_STRING(NS_EG "s")); const SerdNode* const p = serd_nodes_uri(nodes, SERD_STRING(NS_EG "p")); const SerdNode* const o = serd_nodes_uri(nodes, SERD_STRING(NS_EG "o")); const SerdNode* const g = serd_nodes_uri(nodes, SERD_STRING(NS_EG "g")); SerdCaret* const caret = serd_caret_new(f, 1, 1); SerdStatement* const statement = serd_statement_new(s, p, o, g, caret); SerdStatement* const copy = serd_statement_copy(statement); assert(serd_statement_equals(copy, statement)); assert(serd_caret_equals(serd_statement_caret(copy), caret)); serd_statement_free(copy); serd_caret_free(caret); serd_statement_free(statement); serd_nodes_free(nodes); } static void test_free(void) { serd_statement_free(NULL); } static void test_fields(void) { SerdNodes* const nodes = serd_nodes_new(); const SerdNode* const f = serd_nodes_string(nodes, SERD_STRING("file")); const SerdNode* const s = serd_nodes_uri(nodes, SERD_STRING(NS_EG "s")); const SerdNode* const p = serd_nodes_uri(nodes, SERD_STRING(NS_EG "p")); const SerdNode* const o = serd_nodes_uri(nodes, SERD_STRING(NS_EG "o")); const SerdNode* const g = serd_nodes_uri(nodes, SERD_STRING(NS_EG "g")); SerdCaret* const caret = serd_caret_new(f, 1, 1); SerdStatement* const statement = serd_statement_new(s, p, o, g, caret); assert(serd_statement_equals(statement, statement)); assert(!serd_statement_equals(statement, NULL)); assert(!serd_statement_equals(NULL, statement)); assert(serd_statement_node(statement, SERD_SUBJECT) == s); assert(serd_statement_node(statement, SERD_PREDICATE) == p); assert(serd_statement_node(statement, SERD_OBJECT) == o); assert(serd_statement_node(statement, SERD_GRAPH) == g); assert(serd_statement_subject(statement) == s); assert(serd_statement_predicate(statement) == p); assert(serd_statement_object(statement) == o); assert(serd_statement_graph(statement) == g); assert(serd_statement_caret(statement) != caret); assert(serd_caret_equals(serd_statement_caret(statement), caret)); SerdStatement* const diff_s = serd_statement_new(o, p, o, g, caret); assert(!serd_statement_equals(statement, diff_s)); serd_statement_free(diff_s); SerdStatement* const diff_p = serd_statement_new(s, o, o, g, caret); assert(!serd_statement_equals(statement, diff_p)); serd_statement_free(diff_p); SerdStatement* const diff_o = serd_statement_new(s, p, s, g, caret); assert(!serd_statement_equals(statement, diff_o)); serd_statement_free(diff_o); SerdStatement* const diff_g = serd_statement_new(s, p, o, s, caret); assert(!serd_statement_equals(statement, diff_g)); serd_statement_free(diff_g); serd_statement_free(statement); serd_caret_free(caret); serd_nodes_free(nodes); } int main(void) { test_copy(); test_free(); test_fields(); return 0; }