Exemplo n.º 1
0
static void
test_base64_encode(void)
{
    const char base64_map[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    const char instr[] = "This is a message that is multiple of 3 chars";
    const char *expectstrs[] = {
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYXJz",
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYXI=",
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYQ==",
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNo"
    };
    struct sol_str_slice slice;
    char outstr[(sizeof(instr) / 3 + 1) * 4 + 1];
    size_t r, i;

    slice = sol_str_slice_from_str(instr);

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(expectstrs); i++) {
        struct sol_str_slice exp = sol_str_slice_from_str(expectstrs[i]);

        memset(outstr, 0xff, sizeof(outstr));
        r = sol_util_base64_encode(outstr, sizeof(outstr), slice, base64_map);
        ASSERT_INT_EQ(r, exp.len);
        ASSERT_INT_EQ(outstr[r], (char)0xff);
        outstr[r] = '\0';
        ASSERT_STR_EQ(outstr, exp.data);

        slice.len--;
    }
}
Exemplo n.º 2
0
SOL_API void
sol_log_level_to_str(uint8_t level, char *buf, size_t buflen)
{
    static const char *level_names[] = {
        [SOL_LOG_LEVEL_CRITICAL] = "CRI",
        [SOL_LOG_LEVEL_ERROR] = "ERR",
        [SOL_LOG_LEVEL_WARNING] = "WRN",
        [SOL_LOG_LEVEL_INFO] = "INF",
        [SOL_LOG_LEVEL_DEBUG] = "DBG"
    };

    SOL_LOG_INIT_CHECK("level=%hhu, buf=%p, buflen=%zd", level, buf, buflen);
    if (buflen < 1)
        return;

    if (level < SOL_UTIL_ARRAY_SIZE(level_names)) {
        if (level_names[level]) {
            strncpy(buf, level_names[level], buflen - 1);
            buf[buflen - 1] = '\0';
            return;
        }
    }

    snprintf(buf, buflen, "%03d", level);
}
Exemplo n.º 3
0
static void
sol_mavlink_armed_transition(struct sol_mavlink *mavlink, uint8_t base_mode)
{
    uint8_t i, mask = 0;

    if (mavlink->custom_mode_enabled)
        mask = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(armed_transitions); i++) {
        uint8_t from, to;
        const struct sol_mavlink_armed_trans *curr = &armed_transitions[i];

        from = curr->from | mask;
        to = curr->to | mask;

        if (from != mavlink->base_mode || to != base_mode)
            continue;

        if (curr->armed) {
            if (CHECK_HANDLER(mavlink, armed))
                HANDLERS(mavlink)->armed((void *)mavlink->data, mavlink);
        } else {
            if (CHECK_HANDLER(mavlink, disarmed))
                HANDLERS(mavlink)->disarmed((void *)mavlink->data, mavlink);
        }

        break;
    }

    mavlink->base_mode = base_mode;
}
Exemplo n.º 4
0
static void
test_align_power2(void)
{
    unsigned int i;

    static const struct {
        unsigned int input;
        unsigned int output;
    } table[] = {
        { 0, 0 },
        { 1, 1 },
        { 2, 2 },
        { 3, 4 },
        { 4, 4 },
        { 5, 8 },
        { 6, 8 },
        { 7, 8 },
        { 8, 8 },
        { 15, 16 },
        { 16, 16 },
        { 17, 32 },
    };

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(table); i++) {
        unsigned int actual;
        actual = align_power2(table[i].input);

        if (actual != table[i].output) {
            fprintf(stderr, "Error calling align_power2(%u), got %u but expected %u\n",
                table[i].input, actual, table[i].output);
            ASSERT(false);
        }
    }
}
Exemplo n.º 5
0
static void
on_fork(void *data)
{
    unsigned i;

    static const char *daemon_possible_paths[] = {
        "/usr/libexec/bluetooth/bluetoothd", // fedora/yocto-style
        "/usr/lib/bluetooth/bluetoothd", // arch-style
        "/usr/sbin/bluetoothd" // debian-style
    };

    const char *argv[] = {
        NULL, // waiting to be set
        "--nodetach",
        NULL
    };

    static const char *envp[] = {
        "BLUETOOTH_SYSTEM_BUS_ADDRESS=unix:path=/run/dbus/system_bus_socket",
        NULL
    };

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(daemon_possible_paths); i++) {
        argv[0] = daemon_possible_paths[i];
        SOL_INF("attempting to exec %s", daemon_possible_paths[i]);
        execvpe(argv[0], (char *const *)argv, (char *const *)envp);
    }

    SOL_INF("bluetooth daemon executable not found, aborting");
    sol_platform_linux_fork_run_exit(EXIT_FAILURE);
}
Exemplo n.º 6
0
static int
_set_gpio(const uint32_t pin, const enum sol_gpio_direction dir)
{
    if (ardu_breakout)
        return mux_set_gpio(pin, dir, gpio_dev_0, (uint32_t)SOL_UTIL_ARRAY_SIZE(gpio_dev_0));

    return 0;
}
Exemplo n.º 7
0
static int
_set_i2c(const uint8_t bus)
{
    if (ardu_breakout)
        return mux_set_i2c(bus, i2c_dev_0, SOL_UTIL_ARRAY_SIZE(i2c_dev_0));

    return 0;
}
Exemplo n.º 8
0
static int
_set_pwm(const int device, const int channel)
{
    if (ardu_breakout)
        return mux_set_pwm(device, channel, pwm_controller_list, (int)SOL_UTIL_ARRAY_SIZE(pwm_controller_list));

    return 0;
}
Exemplo n.º 9
0
static int
_set_aio(const int device, const int pin)
{
    if (ardu_breakout)
        return mux_set_aio(device, pin, aio_controller_list, (int)SOL_UTIL_ARRAY_SIZE(aio_controller_list));

    return 0;
}
Exemplo n.º 10
0
SOL_API const char *
sol_uart_stop_bits_to_str(enum sol_uart_stop_bits stop_bits)
{
    static const char *stop_bits_names[] = {
        [SOL_UART_STOP_BITS_ONE] = "stopbits-1",
        [SOL_UART_STOP_BITS_TWO] = "stopbits-2"
    };

    if (stop_bits < SOL_UTIL_ARRAY_SIZE(stop_bits_names))
        return stop_bits_names[stop_bits];

    return NULL;
}
Exemplo n.º 11
0
SOL_API const char *
sol_uart_parity_to_str(enum sol_uart_parity parity)
{
    static const char *parity_names[] = {
        [SOL_UART_PARITY_NONE] = "none",
        [SOL_UART_PARITY_EVEN] = "even",
        [SOL_UART_PARITY_ODD] = "odd"
    };

    if (parity < SOL_UTIL_ARRAY_SIZE(parity_names))
        return parity_names[parity];

    return NULL;
}
Exemplo n.º 12
0
SOL_API const char *
sol_bt_transport_to_str(enum sol_bt_transport transport)
{
    static const char *transports[] = {
        [SOL_BT_TRANSPORT_ALL] = "all",
        [SOL_BT_TRANSPORT_LE] = "le",
        [SOL_BT_TRANSPORT_BREDR] = "bredr",
    };

    if (transport < SOL_UTIL_ARRAY_SIZE(transports))
        return transports[transport];

    return NULL;
}
Exemplo n.º 13
0
// 37 = 2 * 16 (chars) + 4 (hyphens) + 1 (\0)
SOL_API int
sol_util_uuid_gen(bool upcase,
    bool with_hyphens,
    char id[SOL_STATIC_ARRAY_SIZE(37)])
{
    static struct sol_str_slice hyphen = SOL_STR_SLICE_LITERAL("-");
    /* hyphens on positions 8, 13, 18, 23 (from 0) */
    static const int hyphens_pos[] = { 8, 13, 18, 23 };
    struct sol_uuid uuid = { { 0 } };
    unsigned i;
    int r;

    struct sol_buffer buf = { 0 };

    sol_buffer_init_flags(&buf, id, 37,
        SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED);

    r = uuid_gen(&uuid);
    SOL_INT_CHECK(r, < 0, r);

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(uuid.bytes); i++) {
        r = sol_buffer_append_printf(&buf, upcase ? "%02hhX" : "%02hhx",
            uuid.bytes[i]);
        SOL_INT_CHECK_GOTO(r, < 0, err);
    }

    if (with_hyphens) {
        for (i = 0; i < SOL_UTIL_ARRAY_SIZE(hyphens_pos); i++) {
            r = sol_buffer_insert_slice(&buf, hyphens_pos[i], hyphen);
            SOL_INT_CHECK_GOTO(r, < 0, err);
        }
    }

err:
    sol_buffer_fini(&buf);
    return r;
}
Exemplo n.º 14
0
SOL_API const char *
sol_uart_data_bits_to_str(enum sol_uart_data_bits data_bits)
{
    static const char *data_bits_names[] = {
        [SOL_UART_DATA_BITS_8] = "databits-8",
        [SOL_UART_DATA_BITS_7] = "databits-7",
        [SOL_UART_DATA_BITS_6] = "databits-6",
        [SOL_UART_DATA_BITS_5] = "databits-5"
    };

    if (data_bits < SOL_UTIL_ARRAY_SIZE(data_bits_names))
        return data_bits_names[data_bits];

    return NULL;
}
Exemplo n.º 15
0
SOL_API const char *
sol_uart_baud_rate_to_str(enum sol_uart_baud_rate baud_rate)
{
    static const char *baud_rate_names[] = {
        [SOL_UART_BAUD_RATE_9600] = "baud-9600",
        [SOL_UART_BAUD_RATE_19200] = "baud-19200",
        [SOL_UART_BAUD_RATE_38400] = "baud-38400",
        [SOL_UART_BAUD_RATE_57600] = "baud-57600",
        [SOL_UART_BAUD_RATE_115200] = "baud-115200"
    };

    if (baud_rate < SOL_UTIL_ARRAY_SIZE(baud_rate_names))
        return baud_rate_names[baud_rate];

    return NULL;
}
int
sol_mainloop_impl_platform_init(void)
{
    int i;

    sol_mainloop_zephyr_common_init();

    nano_fifo_init(&_sol_mainloop_pending_events);
    nano_fifo_init(&_sol_mainloop_free_events);
    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(_events); i++) {
        struct me_fifo_entry *mfe;

        mfe = &_events[i];
        nano_fifo_put(&_sol_mainloop_free_events, mfe);
    }

    return 0;
}
Exemplo n.º 17
0
static void
test_base64_decode(void)
{
    const char base64_map[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    char expstr[] = "This is a message that is multiple of 3 chars";
    const char *instrs[] = {
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYXJz",
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYXI=",
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYQ==",
        "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNo"
    };
    struct sol_str_slice exp, slice;
    char outstr[sizeof(expstr)];
    size_t r, i;

    exp = sol_str_slice_from_str(expstr);

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(instrs); i++) {
        slice = sol_str_slice_from_str(instrs[i]);

        memset(outstr, 0xff, sizeof(outstr));
        r = sol_util_base64_decode(outstr, sizeof(outstr), slice, base64_map);
        ASSERT_INT_EQ(r, exp.len);
        ASSERT_INT_EQ(outstr[r], (char)0xff);
        outstr[r] = '\0';
        ASSERT_STR_EQ(outstr, exp.data);

        exp.len--;
        expstr[exp.len] = '\0';
    }

    /* negative test (invalid char) */
    slice = sol_str_slice_from_str("****");
    memset(outstr, 0xff, sizeof(outstr));
    r = sol_util_base64_decode(outstr, sizeof(outstr), slice, base64_map);
    ASSERT_INT_EQ(r, -EINVAL);

    /* short sequence (not multiple of 4) */
    slice = sol_str_slice_from_str("123");
    memset(outstr, 0xff, sizeof(outstr));
    r = sol_util_base64_decode(outstr, sizeof(outstr), slice, base64_map);
    ASSERT_INT_EQ(r, -EINVAL);
}
Exemplo n.º 18
0
SOL_API int
sol_flow_node_named_options_parse_member(
    struct sol_flow_node_named_options_member *m,
    const char *value,
    const struct sol_flow_node_options_member_description *mdesc)
{
    int r;

    if (!m) {
        SOL_DBG("Options member must be a valid pointer.");
        return -EINVAL;
    }

    if (!mdesc) {
        SOL_DBG("Options member description must be a valid pointer.");
        return -EINVAL;
    }

    if (m->type == 0) {
        r = -EINVAL;
        SOL_DBG("Unitialized member type for name=\"%s\": \"%s\"", m->name, value);
    } else if (m->type < SOL_UTIL_ARRAY_SIZE(options_parse_functions)) {
        if (mdesc->required)
            init_member_suboptions(m);
        else
            set_default_option(m, mdesc);

        r = options_parse_functions[m->type](value, m);
        if (r < 0) {
            SOL_DBG("Invalid value '%s' for option name='%s' of type='%s'",
                value, m->name, sol_flow_node_options_member_type_to_string(m->type));
        }
    } else {
        r = -ENOTSUP;
        SOL_DBG("Invalid option member type for name=\"%s\": \"%s\"", m->name, value);
    }

    return r;
}
Exemplo n.º 19
0
static void
_kcmdline_parse_var(const char *start, size_t len)
{
    static const struct spec {
        const char *prefix;
        size_t prefixlen;
        void *data;
        void (*parse)(const char *str, size_t size, void *data);
    } specs[] = {
#define SPEC(str, storage, parse)               \
    { str, sizeof(str) - 1, storage, parse \
    }
        SPEC("LEVELS", NULL, _levels_parse_wrapper),
        SPEC("LEVEL", &_global_domain.level, _level_parse_wrapper),
        SPEC("ABORT", &_abort_level, _level_parse_wrapper),
        SPEC("SHOW_COLORS", &_show_colors, _bool_parse_wrapper),
        SPEC("SHOW_FILE", &_show_file, _bool_parse_wrapper),
        SPEC("SHOW_FUNCTION", &_show_function, _bool_parse_wrapper),
        SPEC("SHOW_LINE", &_show_line, _bool_parse_wrapper),
#undef SPEC
    };
    const struct spec *itr, *itr_end;

    itr = specs;
    itr_end = itr + SOL_UTIL_ARRAY_SIZE(specs);
    for (; itr < itr_end; itr++) {
        if (itr->prefixlen + 1 < len &&
            memcmp(itr->prefix, start, itr->prefixlen) == 0 &&
            start[itr->prefixlen] == '=') {
            itr->parse(start + (itr->prefixlen + 1),
                len - (itr->prefixlen + 1),
                itr->data);
            break;
        }
    }
}
Exemplo n.º 20
0
static void
test_split_urls(void)
{
#define SET_PARAMS(_url, _scheme, _user, _pass, _host, _path, _query, _fragment, _port, _result, _check_url) \
    { SOL_STR_SLICE_LITERAL(_url), { SOL_STR_SLICE_LITERAL(_scheme), SOL_STR_SLICE_LITERAL(_user), SOL_STR_SLICE_LITERAL(_pass), \
                                     SOL_STR_SLICE_LITERAL(_host), SOL_STR_SLICE_LITERAL(_path), \
                                     SOL_STR_SLICE_LITERAL(_query), SOL_STR_SLICE_LITERAL(_fragment), _port }, _result, _check_url }
    size_t i;
    int r;
    static const struct {
        struct sol_str_slice url;
        struct sol_http_url splitted_url;
        int result;
        bool check_url;
    } test_split[] =  {
        SET_PARAMS("http://[2001:db8::1]", "http", "", "", "2001:db8::1", "", "", "", 0, 0, true),
        SET_PARAMS("http://*****:*****@[::1]:123/a/b?p=1&c=2#/a/b", "foo", "user", "pass", "::1", "/a/b", "p=1&c=2", "/a/b", 123, 0, true),
        SET_PARAMS("foo://user@[::1]:123/a/b?p=1&c=2#/a/b", "foo", "user", "", "::1", "/a/b", "p=1&c=2", "/a/b", 123, 0, true),
        SET_PARAMS("foo://user:@[::1]:123/a/b?p=1&c=2#/a/b", "foo", "user", "", "::1", "/a/b", "p=1&c=2", "/a/b", 123, 0, false),
        SET_PARAMS("foo://[::1]:123/a/b?p=1&c=2#/a/b", "foo", "", "", "::1", "/a/b", "p=1&c=2", "/a/b", 123, 0, true),
        SET_PARAMS("foo://[::1]/a/b?p=1&c=2#/a/b", "foo", "", "", "::1", "/a/b", "p=1&c=2", "/a/b", 0, 0, true),
        SET_PARAMS("foo://[::1]/?p=1&c=2#/a/b", "foo", "", "", "::1", "/", "p=1&c=2", "/a/b", 0, 0, true),
        SET_PARAMS("foo://[::1]/?p=1&c=2", "foo", "", "", "::1", "/", "p=1&c=2", "", 0, 0, true),
        SET_PARAMS("foo://[::1]/#/a/b", "foo", "", "", "::1", "/", "", "/a/b", 0, 0, true),
        SET_PARAMS("foo://[::1]?p=1&c=2", "foo", "", "", "::1", "", "p=1&c=2", "", 0, 0, true),
        SET_PARAMS("foo://[::1]#/a/b", "foo", "", "", "::1", "", "", "/a/b", 0, 0, true),
        SET_PARAMS("foo://[::1]:123/#/a/b", "foo", "", "", "::1", "/", "", "/a/b", 123, 0, true),
        SET_PARAMS("file://[::1]/usr/home/user/hi.txt", "file", "", "", "::1", "/usr/home/user/hi.txt", "", "", 0, 0, true),
        SET_PARAMS("foo://[::1]/?go", "foo", "", "", "::1", "/", "go", "", 0, 0, true),
        SET_PARAMS("foo://:password@[::1]", "foo", "", "password", "::1", "", "", "", 0, 0, true),
        SET_PARAMS("foo://:@[::1]", "foo", "", "", "::1", "", "", "", 0, 0, false),
        SET_PARAMS("foo://@[::1]", "foo", "", "", "::1", "", "", "", 0, 0, false),

        SET_PARAMS("www.intel.com.br", "", "", "", "", "", "", "", 0, -EINVAL, false),
        SET_PARAMS(":www.intel.com", "", "", "", "", "", "", "", 0, -EINVAL, false),
        SET_PARAMS("//www.intel.com", "", "", "", "", "", "", "", 0, -EINVAL, false),
        SET_PARAMS("://www.intel.com", "", "", "", "", "", "", "", 0, -EINVAL, false),
        SET_PARAMS("/a/b", "", "", "", "", "", "", "", 0, -EINVAL, false),
        SET_PARAMS("//a/b", "", "", "", "", "", "", "", 0, -EINVAL, false),
        SET_PARAMS("http://", "", "", "", "", "", "", "", 0, -EINVAL, false),
        SET_PARAMS("http://www.intel.com:/", "http", "", "", "www.intel.com", "/", "", "", 0, 0, false),
        SET_PARAMS("http://intel.com/?go=2", "http", "", "", "intel.com", "/", "go=2", "", 0, 0, true),
        SET_PARAMS("http://www.intel.com:8080", "http", "", "", "www.intel.com", "", "", "", 8080, 0, true),
        SET_PARAMS("http://www.intel.com:1234/", "http", "", "", "www.intel.com", "/", "", "", 1234, 0, true),
        SET_PARAMS("http://www.intel.com/a/b/d?go=2#fragment", "http", "", "", "www.intel.com", "/a/b/d", "go=2", "fragment", 0, 0, true),
        SET_PARAMS("foo://*****:*****@server.com:123/a/b?p=1&c=2#/a/b", "foo", "user", "pass", "server.com", "/a/b", "p=1&c=2", "/a/b", 123, 0, true),
        SET_PARAMS("foo://[email protected]:123/a/b?p=1&c=2#/a/b", "foo", "user", "", "server.com", "/a/b", "p=1&c=2", "/a/b", 123, 0, true),
        /* Do not check the created url for this one, Altought the created one will be correct it will not match,
           as the create url will be foo://user:@server.com:123/a/b?p=1&c=2#/a/b
           This behaviour is acceptable, since ':' can be ommited if the password is not provided.
         */
        SET_PARAMS("foo://user:@server.com:123/a/b?p=1&c=2#/a/b", "foo", "user", "", "server.com", "/a/b", "p=1&c=2", "/a/b", 123, 0, false),
        SET_PARAMS("foo://server.com:123/a/b?p=1&c=2#/a/b", "foo", "", "", "server.com", "/a/b", "p=1&c=2", "/a/b", 123, 0, true),
        SET_PARAMS("foo://server.com/a/b?p=1&c=2#/a/b", "foo", "", "", "server.com", "/a/b", "p=1&c=2", "/a/b", 0, 0, true),
        SET_PARAMS("foo://server.com/?p=1&c=2#/a/b", "foo", "", "", "server.com", "/", "p=1&c=2", "/a/b", 0, 0, true),
        SET_PARAMS("foo://server.com/?p=1&c=2", "foo", "", "", "server.com", "/", "p=1&c=2", "", 0, 0, true),
        SET_PARAMS("foo://server.com/#/a/b", "foo", "", "", "server.com", "/", "", "/a/b", 0, 0, true),
        SET_PARAMS("foo://server.com?p=1&c=2", "foo", "", "", "server.com", "", "p=1&c=2", "", 0, 0, true),
        SET_PARAMS("foo://server.com#/a/b", "foo", "", "", "server.com", "", "", "/a/b", 0, 0, true),
        SET_PARAMS("foo://192.3.3.3:123/#/a/b", "foo", "", "", "192.3.3.3", "/", "", "/a/b", 123, 0, true),
        SET_PARAMS("mailto:[email protected]", "mailto", "", "", "", "*****@*****.**", "", "", 0, 0, true),
        SET_PARAMS("file://localhost/usr/home/user/hi.txt", "file", "", "", "localhost", "/usr/home/user/hi.txt", "", "", 0, 0, true),
        SET_PARAMS("foo://localhost/?go", "foo", "", "", "localhost", "/", "go", "", 0, 0, true),
        SET_PARAMS("foo://:password@localhost", "foo", "", "password", "localhost", "", "", "", 0, 0, true),
        SET_PARAMS("foo://:@localhost", "foo", "", "", "localhost", "", "", "", 0, 0, false),
        SET_PARAMS("foo://@localhost", "foo", "", "", "localhost", "", "", "", 0, 0, false),
    };

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(test_split); i++) {
        struct sol_http_url splitted;
        struct sol_http_params params;
        struct sol_buffer out_uri = SOL_BUFFER_INIT_EMPTY;

        r = sol_http_split_uri(test_split[i].url, &splitted);
        ASSERT_INT_EQ(r, test_split[i].result);
        if (test_split[i].result < 0)
            continue;
        ASSERT(sol_str_slice_eq(splitted.scheme, test_split[i].splitted_url.scheme));
        ASSERT(sol_str_slice_eq(splitted.host, test_split[i].splitted_url.host));
        ASSERT(sol_str_slice_eq(splitted.path, test_split[i].splitted_url.path));
        ASSERT(sol_str_slice_eq(splitted.fragment, test_split[i].splitted_url.fragment));
        ASSERT(sol_str_slice_eq(splitted.query, test_split[i].splitted_url.query));
        ASSERT(sol_str_slice_eq(splitted.user, test_split[i].splitted_url.user));
        ASSERT(sol_str_slice_eq(splitted.password, test_split[i].splitted_url.password));
        ASSERT_INT_EQ(splitted.port, test_split[i].splitted_url.port);
        if (!test_split[i].check_url)
            continue;
        sol_http_params_init(&params);
        r = sol_http_decode_params(splitted.query, SOL_HTTP_PARAM_QUERY_PARAM, &params);
        ASSERT_INT_EQ(r, 0);
        r = sol_http_create_uri(&out_uri, splitted, &params);
        ASSERT_INT_EQ(r, 0);
        ASSERT(sol_str_slice_eq(test_split[i].url, sol_buffer_get_slice(&out_uri)));
        sol_http_params_clear(&params);
        sol_buffer_fini(&out_uri);
    }

#undef SET_PARAMS
}
Exemplo n.º 21
0
static void
test_unicode_utf_conversion(void)
{
    const char utf8_string[] = "Unicode ÀÊ�öúĎǧɵܢވ࡞शཌ�♎☀⚑€♫��鿿�";
    const uint8_t invalid_utf8[][4] = {
        { 0xA0, 0x01, 0x0, 0x0 },
        { 0xA0, 0xFF, 0x0, 0x0 },
        { 0xE5, 0x01, 0x80, 0x0 },
        { 0xE5, 0xFF, 0x80, 0x0 },
        { 0xE5, 0x80, 0x01, 0x0 },
        { 0xE5, 0x80, 0xFF, 0x0 },
        { 0xF2, 0x0, 0x0, 0x0 },
        { 0xF0, 0x0, 0x0, 0x0 },
        { 0xF0, 0x90, 0x0, 0x0 },
        { 0xF0, 0x90, 0x80, 0x0 },
    };
    uint8_t utf8_buf[4];
    const int32_t unicode_codes[] = {
        0x0055, 0x006E, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065, 0x0020, 0x00c0,
        0x00CA, 0x00CD, 0x00f6, 0x00FA, 0x010e, 0x01e7, 0x0275, 0x0722, 0x0788,
        0x085E, 0x0936, 0x0f4c, 0x2764, 0x264e, 0x2600, 0x2691, 0x20ac, 0x266b,
        0x10123, 0x10fff, 0x9fff, 0x10000, 0x0
    };

    size_t i, str_len, r;
    const uint8_t *p = (const uint8_t *)utf8_string;
    int32_t code;
    uint8_t read, written;

    str_len = sizeof(utf8_string);
    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(unicode_codes); i++) {
        code = sol_util_unicode_code_from_utf8(p, str_len, &read);
        ASSERT_INT_EQ(code, unicode_codes[i]);

        written = sol_util_utf8_from_unicode_code(utf8_buf, 4,
            unicode_codes[i]);
        ASSERT_INT_EQ(read, written);
        ASSERT_INT_EQ(memcmp(utf8_buf, p, written), 0);

        p += read;
        str_len += read;

    }

    //Invalid values
    r = sol_util_utf8_from_unicode_code(utf8_buf, 4, 0x110000);
    ASSERT_INT_EQ(r, -EINVAL);
    r = sol_util_utf8_from_unicode_code(utf8_buf, 3, 0x10000);
    ASSERT_INT_EQ(r, -EINVAL);
    r = sol_util_utf8_from_unicode_code(utf8_buf, 2, 0x0800);
    ASSERT_INT_EQ(r, -EINVAL);
    r = sol_util_utf8_from_unicode_code(utf8_buf, 1, 0x080);
    ASSERT_INT_EQ(r, -EINVAL);
    r = sol_util_utf8_from_unicode_code(utf8_buf, 0, 0x0);
    ASSERT_INT_EQ(r, -EINVAL);

    for (i = 0; i < SOL_UTIL_ARRAY_SIZE(invalid_utf8); i++) {
        code = sol_util_unicode_code_from_utf8(invalid_utf8[i],
            sizeof(invalid_utf8[i]), NULL);
        ASSERT_INT_EQ(code, -EINVAL);
    }
}
Exemplo n.º 22
0
static int
_set_aio(const int device, const int pin)
{
    return mux_set_aio(device, pin, aio_controller_list, (int)SOL_UTIL_ARRAY_SIZE(aio_controller_list));
}
Exemplo n.º 23
0
static int
_set_i2c(const uint8_t bus)
{
    return mux_set_i2c(bus, i2c_dev_0, SOL_UTIL_ARRAY_SIZE(i2c_dev_0));
}
Exemplo n.º 24
0
static int
_set_pwm(const int device, const int channel)
{
    return mux_set_pwm(device, channel, pwm_controller_list, (int)SOL_UTIL_ARRAY_SIZE(pwm_controller_list));
}
Exemplo n.º 25
0
};

// =============================================================================
// Edison Multiplexers
// =============================================================================

//AIO

// Recipe List for AIO device 1
static const struct mux_description *const aio_dev_1[] = {
    desc_14, desc_15, desc_16, desc_17, desc_18, desc_19
};

static const struct mux_controller aio_controller_list[] = {
    { 0, NULL },
    { SOL_UTIL_ARRAY_SIZE(aio_dev_1), aio_dev_1 },
};

//GPIO
static const struct mux_description *const gpio_dev_0[184] = {
    [12] = desc_3,
    [13] = desc_5,
    [14] = desc_18,
    [40] = desc_13,
    [41] = desc_10,
    [42] = desc_12,
    [43] = desc_11,
    [44] = desc_14,
    [45] = desc_15,
    [46] = desc_16,
    [47] = desc_17,