Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run formatting job and add it to CI #55

Open
wants to merge 9 commits into
base: ari-handling-updates
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ on:
pull_request: {} # any target

jobs:
check-formatting:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Set up OS
run: >
sudo apt-get update && sudo apt-get install -y
clang-format
- name: Check code formatting
run: ./check_format.sh
unit-test:
runs-on: ubuntu-22.04
steps:
Expand Down
11 changes: 11 additions & 0 deletions check_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
./apply_format.sh
changed=$(git status -s | grep "^ M ")

if [ ! -z "${changed}" ]; then
echo "Error: Files changed after formatting:"
git diff
exit 1
fi

true
16 changes: 8 additions & 8 deletions src/cace/amm/typing.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,30 +526,30 @@ static int builtin_real64_convert(const amm_type_t *self, ari_t *out, const ari_
static bool builtin_time_constraints(struct timespec *out, const ari_t *ari)
{
const ari_lit_t *obj = &(ari->as_lit);
struct timespec value;
struct timespec value;
switch (obj->prim_type)
{
case ARI_PRIM_UINT64:
value.tv_sec = obj->value.as_uint64;
value.tv_sec = obj->value.as_uint64;
value.tv_nsec = 0;
break;
case ARI_PRIM_INT64:
value.tv_sec = obj->value.as_int64;
value.tv_sec = obj->value.as_int64;
value.tv_nsec = 0;
break;
case ARI_PRIM_FLOAT64:
{
double v = obj->value.as_float64;
if (isnan(v) || isinf(v) || v > INT64_MAX || v < INT64_MIN)
{
return false;
return false;
}

double integral;
double frac = modf(v, &integral);

value.tv_sec = (time_t) integral;
value.tv_nsec = (time_t) (frac * 1000000000);
value.tv_sec = (time_t)integral;
value.tv_nsec = (time_t)(frac * 1000000000);
break;
}
case ARI_PRIM_TIMESPEC:
Expand Down Expand Up @@ -578,8 +578,8 @@ static int builtin_time_convert(const amm_type_t *self, ari_t *out, const ari_t
{
return CACE_AMM_ERR_CONVERT_BADVALUE;
}
else if ((self->as_builtin.ari_type == ARI_TYPE_TP && in->as_lit.ari_type == ARI_TYPE_TD) ||
(self->as_builtin.ari_type == ARI_TYPE_TD && in->as_lit.ari_type == ARI_TYPE_TP))
else if ((self->as_builtin.ari_type == ARI_TYPE_TP && in->as_lit.ari_type == ARI_TYPE_TD)
|| (self->as_builtin.ari_type == ARI_TYPE_TD && in->as_lit.ari_type == ARI_TYPE_TP))
{
return CACE_AMM_ERR_CONVERT_BADVALUE;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cace/ari/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void ari_objpath_copy(ari_objpath_t *obj, const ari_objpath_t *src)

static bool ari_valid_type_for_objpath(ari_type_t type)
{
return (type < ARI_TYPE_NULL && type != ARI_TYPE_OBJECT);
return (type < ARI_TYPE_NULL && type != ARI_TYPE_OBJECT);
}

int ari_objpath_derive_type(ari_objpath_t *path)
Expand All @@ -239,7 +239,7 @@ int ari_objpath_derive_type(ari_objpath_t *path)
path->ari_type = found;
if (!ari_valid_type_for_objpath(found))
{
return 3; // Invalid ARI
return 3; // Invalid ARI
}
}
break;
Expand All @@ -248,7 +248,7 @@ int ari_objpath_derive_type(ari_objpath_t *path)
{
if (!ari_valid_type_for_objpath(path->type_id.as_int))
{
return 3; // Invalid ARI
return 3; // Invalid ARI
}

// validate the ID by getting a static name
Expand Down
16 changes: 10 additions & 6 deletions src/cace/ari/text_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,19 +668,23 @@ void strip_space(string_t out, const char *in, size_t in_len)
strip_chars(out, in, in_len, " \b\f\n\r\t");
}

void cace_string_tolower(string_t out) {
void cace_string_tolower(string_t out)
{
CHKVOID(out);
size_t len = string_size(out);
for (size_t i = 0; i < len; i++) {
string_set_char(out, i, tolower(string_get_char(out, i)));
for (size_t i = 0; i < len; i++)
{
string_set_char(out, i, tolower(string_get_char(out, i)));
}
}

void cace_string_toupper(string_t out) {
void cace_string_toupper(string_t out)
{
CHKVOID(out);
size_t len = string_size(out);
for (size_t i = 0; i < len; i++) {
string_set_char(out, i, toupper(string_get_char(out, i)));
for (size_t i = 0; i < len; i++)
{
string_set_char(out, i, toupper(string_get_char(out, i)));
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/cace/util/nocase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
*/
static inline size_t m_core_cstr_nocase_hash(const char str[])
{
M_HASH_DECL(hash);
while (*str) {
unsigned long u = tolower((unsigned char) *str++);
M_HASH_UP(hash, u);
}
return M_HASH_FINAL(hash);
M_HASH_DECL(hash);
while (*str)
{
unsigned long u = tolower((unsigned char)*str++);
M_HASH_UP(hash, u);
}
return M_HASH_FINAL(hash);
}

#define M_CSTR_NOCASE_HASH(s) (m_core_cstr_nocase_hash(s))
Expand All @@ -45,7 +46,8 @@ static inline size_t m_core_cstr_nocase_hash(const char str[])
* This is intended to be used as dict/tree keys of type "const char *" with
* external memory management.
*/
#define M_CSTR_NOCASE_OPLIST M_OPEXTEND(M_CSTR_OPLIST, HASH(M_CSTR_NOCASE_HASH), EQUAL(M_CSTR_NOCASE_EQUAL), CMP(strcasecmp))
#define M_CSTR_NOCASE_OPLIST \
M_OPEXTEND(M_CSTR_OPLIST, HASH(M_CSTR_NOCASE_HASH), EQUAL(M_CSTR_NOCASE_EQUAL), CMP(strcasecmp))

/// Case-insensitive comparison
static inline int m_string_nocase_cmp(const m_string_t v1, const m_string_t v2)
Expand Down
4 changes: 2 additions & 2 deletions test/cace/test_amm_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static void check_lookup(const char *inhex, int expect_cbor_decode, int expect_r

if (expect_cbor_decode)
{
ari_deinit(&inval);
return;
ari_deinit(&inval);
return;
}

TEST_ASSERT_TRUE(inval.is_ref);
Expand Down
32 changes: 16 additions & 16 deletions test/cace/test_amm_typing.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,32 +289,32 @@ void test_amm_type_convert_ident(const char *inhex, const char *expecthex)
check_convert(type, inhex, expecthex);
}

TEST_CASE("820C1A2B450625", "820C1A2B450625") // ari:/TP/20230102T030405Z
TEST_CASE("82041864", "820C1864") // ari:/INT/100 -> ari:/TP/100
TEST_CASE("820C1A2B450625", "820C1A2B450625") // ari:/TP/20230102T030405Z
TEST_CASE("82041864", "820C1864") // ari:/INT/100 -> ari:/TP/100
TEST_CASE("8208FB40593F34D6A161E5", "820C82231A000F68D4") // ari:/REAL64/100.9876
TEST_CASE("8209FA7F000000", NULL) // REAL64 exceeds INT64 MAX
TEST_CASE("8209FAEF000000", NULL) // REAL64 less than UINT64 MAX
TEST_CASE("820D1864", NULL) // ari:/TD/100
TEST_CASE("82043863", "820C3863") // ari:/INT/-100
TEST_CASE("8209FA7F000000", NULL) // REAL64 exceeds INT64 MAX
TEST_CASE("8209FAEF000000", NULL) // REAL64 less than UINT64 MAX
TEST_CASE("820D1864", NULL) // ari:/TD/100
TEST_CASE("82043863", "820C3863") // ari:/INT/-100
TEST_CASE("8209FBC0593F34D6A161E5", "820C82233A000F68D3") // ari:/REAL64/-100.9876
TEST_CASE("8209F97C00", NULL) // ari:/real64/Infinity
TEST_CASE("8209F97E00", NULL) // ari:/real64/NaN
TEST_CASE("8209F97C00", NULL) // ari:/real64/Infinity
TEST_CASE("8209F97E00", NULL) // ari:/real64/NaN
void test_amm_type_convert_tp(const char *inhex, const char *expecthex)
{
const amm_type_t *type = amm_type_get_builtin(ARI_TYPE_TP);
check_convert(type, inhex, expecthex);
}

TEST_CASE("820D822018CD", "820D822018CD") // ari:/TD/PT20.5S
TEST_CASE("82041864", "820D1864") // ari:/INT/100 -> ari:/TD/100
TEST_CASE("820D822018CD", "820D822018CD") // ari:/TD/PT20.5S
TEST_CASE("82041864", "820D1864") // ari:/INT/100 -> ari:/TD/100
TEST_CASE("8208FB40593F34D6A161E5", "820D82231A000F68D4") // ari:/REAL64/100.9876
TEST_CASE("8209FA7F000000", NULL) // REAL64 exceeds INT64 MAX
TEST_CASE("8209FAEF000000", NULL) // REAL64 less than UINT64 MAX
TEST_CASE("820C1864", NULL) // ari:/TP/100
TEST_CASE("82043863", "820D3863") // ari:/INT/-100
TEST_CASE("8209FA7F000000", NULL) // REAL64 exceeds INT64 MAX
TEST_CASE("8209FAEF000000", NULL) // REAL64 less than UINT64 MAX
TEST_CASE("820C1864", NULL) // ari:/TP/100
TEST_CASE("82043863", "820D3863") // ari:/INT/-100
TEST_CASE("8208FBC0593F34D6A161E5", "820D82233A000F68D3") // ari:/REAL32/-100.9876
TEST_CASE("8209F97C00", NULL) // ari:/real64/Infinity
TEST_CASE("8209F97E00", NULL) // ari:/real64/NaN
TEST_CASE("8209F97C00", NULL) // ari:/real64/Infinity
TEST_CASE("8209F97E00", NULL) // ari:/real64/NaN
void test_amm_type_convert_td(const char *inhex, const char *expecthex)
{
const amm_type_t *type = amm_type_get_builtin(ARI_TYPE_TD);
Expand Down
4 changes: 2 additions & 2 deletions test/cace/test_ari_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void test_ari_cbor_decode_lit_typed_real64(const char *inhex, bool expect)

TEST_CASE("A0") // bad major type
TEST_CASE("821182A0820417") // AC with item having bad major type
//TEST_CASE("836474657374226474686174") // ari://test/CTRL/that
// TEST_CASE("836474657374226474686174") // ari://test/CTRL/that
TEST_CASE("8364746573740A6474686174") // ari://test/TEXTSTR/that
void test_ari_cbor_decode_failure(const char *inhex)
{
Expand Down Expand Up @@ -498,7 +498,7 @@ TEST_CASE("82041864")
TEST_CASE("82051864")
TEST_CASE("82061864")
TEST_CASE("82071864")
TEST_CASE("8212A303F50A626869626F6804") // ari:/AM/(3=true,10=hi,oh=4) AM key ordering
TEST_CASE("8212A303F50A626869626F6804") // ari:/AM/(3=true,10=hi,oh=4) AM key ordering
TEST_CASE("8464746573742A6474686174811822") // ari://test/-11/that(34)
void test_ari_cbor_loopback(const char *inhex)
{
Expand Down
2 changes: 1 addition & 1 deletion test/cace/test_ari_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ TEST_CASE("ari:/rptset/n=1234;r=/TP/1000.987654321;(t=/TD/0;s=//test/CTRL/hi;(nu
"ari:/RPTSET/n=1234;r=/TP/20000101T001640.987654321Z;(t=/TD/PT0S;s=//test/CTRL/hi;(null,3,h'6869'))")
TEST_CASE("ari:/rptset/n=1234;r=1000.9876543210987654321;(t=/TD/0;s=//test/CTRL/hi;(null,3,h'6869'))",
"ari:/RPTSET/n=1234;r=/TP/20000101T001640.987654321Z;(t=/TD/PT0S;s=//test/CTRL/hi;(null,3,h'6869'))")
TEST_CASE("ari://test", "ari://test/") // always trailing slash
TEST_CASE("ari://test", "ari://test/") // always trailing slash
TEST_CASE("ari:./ctrl/hi", "./CTRL/hi") // scheme elided
void test_ari_text_reencode(const char *intext, const char *expect_outtext)
{
Expand Down