skip to content
==> tests/id.c <==
1/* Job words and hash hex, as jobs.rs writes and reads them. */
2#include "mesh/jobs/id.h"
3#include "mesh/check.h"
4
5int main(void) {
6    char w[MJ_JOB_WORD_MAX];
7    mj_job_word((uint64_t)3 << 32 | 7, w);
8    CHECK_S(w, "3.7");
9    mj_job_word(UINT64_MAX, w);
10    CHECK_S(w, "4294967295.4294967295");
11    mj_job_id id;
12    CHECK(mj_parse_job("3.7", &id) && id == ((uint64_t)3 << 32 | 7));
13    CHECK(mj_parse_job("+1.+2", &id) && id == ((uint64_t)1 << 32 | 2));
14    CHECK(!mj_parse_job("3", &id) && !mj_parse_job("3.", &id) && !mj_parse_job(".3", &id) && !mj_parse_job("3.4294967296", &id));
15    CHECK(!mj_parse_job("1.2.3", &id)); /* "2.3" is not a u32 */
16    mj_hash h;
17    for (int i = 0; i < 32; i++) h.b[i] = (uint8_t)(i * 37 + 1);
18    char x[65];
19    mj_hex(&h, x);
20    CHECK_S(x, "01264b7095badf04294e7398bde2072c51769bc0e50a2f54799ec3e80d32577c");
21    mj_hash back;
22    CHECK(mj_unhex(x, &back) && mj_hash_eq(&back, &h));
23    CHECK(mj_unhex("01264B7095BADF04294E7398BDE2072C51769BC0E50A2F54799EC3E80D32577C", &back) && mj_hash_eq(&back, &h));
24    CHECK(!mj_unhex("0126", &back) && !mj_unhex("zz264b7095badf04294e7398bde2072c5176a0c5ea0f34597ea3c8ed12375c81", &back));
25    uint64_t words[4];
26    mj_hash_words(&h, words);
27    CHECK_U(words[0], 0x01264b7095badf04u);
28    mj_hash again = mj_hash_of_words(words);
29    CHECK(mj_hash_eq(&again, &h));
30    return mesh_check_done();
31}