int main() { //Message 1 assert_int_eq(sizeof(MSG1)-1, len_a = rtosc_message(buffer_a, 256, "/flying-monkey", "s", "bannana"), "Creating Simple Message 1", __LINE__); assert_hex_eq(MSG1, buffer_a, sizeof(MSG1)-1, len_a, "Verifying Content of Message 1", __LINE__); assert_int_eq(0, rtosc_bundle_p(buffer_a), "Simple Message 1 Is Not A Bundle", __LINE__); //Message 2 assert_int_eq(sizeof(MSG2)-1, len_b = rtosc_message(buffer_b, 256, "/foobar-message", "iT", 42), "Creating Simple Message 2", __LINE__); assert_hex_eq(MSG2, buffer_b, sizeof(MSG2)-1, len_b, "Verifying Content of Message 2", __LINE__); assert_int_eq(0, rtosc_bundle_p(buffer_b), "Simple Message 2 Is Not A Bundle", __LINE__); //Bundle 1 assert_int_eq(sizeof(RESULT)-1, len_c = rtosc_bundle(buffer_c, 256, 0, 2, buffer_a, buffer_b), "Creating Bundle 1", __LINE__); assert_int_eq(len_c, rtosc_message_length(buffer_c, len_c), "Verifying Bundle 1's Length", __LINE__); assert_hex_eq(RESULT, buffer_c, sizeof(RESULT)-1, len_c, "Verifying Bundle 1's Content", __LINE__); assert_int_eq(1, rtosc_bundle_p(buffer_c), "Verifying Bundle 1 Is A Bundle", __LINE__); assert_int_eq(2, rtosc_bundle_elements(buffer_c, 256), "Verifying Bundle 2 Has Two Messages", __LINE__); assert_str_eq("/flying-monkey", rtosc_bundle_fetch(buffer_c, 0), "Verifying Message 1 Path", __LINE__); assert_str_eq("/foobar-message", rtosc_bundle_fetch(buffer_c, 1), "Verifying Message 2 Path", __LINE__); //Check minimum bundle size #bundle + time tag assert_int_eq(8+8, rtosc_bundle(buffer_c, 256, 1, 0), "Verify Minimum Legal Bundle Size", __LINE__); //check message length support assert_int_eq(8+8, rtosc_message_length(buffer_c, 256), "Verify rtosc_message_length() on Minimum Bundle", __LINE__); //Verify that timetag can be fetched assert_int_eq(1, rtosc_bundle_timetag(buffer_c), "Verify rtosc_bundle_timetag() Works", __LINE__); return test_summary(); }
/* * The OSC 1.0 spec provides two example messages at * http://opensoundcontrol.org/spec-1_0-examples * * This test verifies that these messages are identically serialized */ int main() { check(rtosc_message(buffer, 256, "/oscillator/4/frequency", "f", 440.0f), "Failed message creation", __LINE__); check(!memcmp(buffer, message_one, sizeof(message_one)), "Message does not meet spec", __LINE__); check(rtosc_message(buffer, 256, "/foo", "iisff", 1000, -1, "hello", 1.234f, 5.678f), "Failed message creation", __LINE__); check(!memcmp(buffer, message_two, sizeof(message_two)), "Message does not meet spec", __LINE__); return 0; }
int main() { //Verify that given a null buffer, it does not segfault assert_int_eq(20, rtosc_message(0,0,"/page/poge","TIF"), "Build A Message With NULL Buffer", __LINE__); return 0; }
//verifies a message with all types included serializes and deserializes int main() { unsigned message_len; int32_t i = 42; //integer float f = 0.25; //float const char *s = "string"; //string rtosc_blob_t b = {3,(uint8_t*)s};//blob int64_t h = -125; //long integer uint64_t t = 22412; //timetag double d = 0.125; //double const char *S = "Symbol"; //symbol char c = 25; //character int32_t r = 0x12345678; //RGBA midi_t m = {0x12,0x23, //midi 0x34,0x45 }; //true //false //nil //inf message_len = rtosc_message(buffer, 1024, "/dest", "[ifsbhtdScrmTFNI]", i,f,s,b.len,b.data,h,t,d,S,c,r,m); assert_int_eq(96, message_len, "Generating A Message With All Arg Types", __LINE__); rtosc_arg_t arg; assert_int_eq(i, rtosc_argument(buffer, 0).i, "Checking 'i' Argument", __LINE__); CHECK(f,f,1); assert_str_eq(s, rtosc_argument(buffer, 2).s, "Checking 's' Argument", __LINE__); CHECK(b.len,b.len,3); assert_hex_eq((char*)b.data, (char*)arg.b.data, 3, b.len, "Checking 'b.data' Argument", __LINE__); CHECK(h,h,4); CHECK(t,t,5); CHECK(d,d,6); assert_str_eq(S,rtosc_argument(buffer, 7).s, "Checking 'S' Argument", __LINE__); assert_char_eq(c,rtosc_argument(buffer, 8).i, "Checking 'c' Argument", __LINE__); CHECK(r,i,9); CHECK(m,m,10); assert_char_eq('T', rtosc_type(buffer,11), "Checking 'T' Argument", __LINE__); assert_char_eq('F', rtosc_type(buffer,12), "Checking 'F' Argument", __LINE__); assert_char_eq('N', rtosc_type(buffer,13), "Checking 'N' Argument", __LINE__); assert_char_eq('I', rtosc_type(buffer,14), "Checking 'I' Argument", __LINE__); assert_true(rtosc_valid_message_p(buffer, message_len), "Verifying Message Is Valid", __LINE__); return test_summary(); }
//verify that empty strings can be retreived int main() { size_t length = rtosc_message(buffer, 1024, "/path", "sss", "", "", ""); // /pat h000 ,sss 0000 0000 0000 0000 assert_int_eq(28, length, "Build Empty String Based Message", __LINE__); assert_non_null(rtosc_argument(buffer, 0).s, "Check Arg 1", __LINE__); assert_non_null(rtosc_argument(buffer, 1).s, "Check Arg 2", __LINE__); assert_non_null(rtosc_argument(buffer, 2).s, "Check Arg 3", __LINE__); return test_summary(); }
int main() { int32_t i = 42; //integer float f = 0.25; //float const char *s = "string"; //string size_t message_size = 32; CHECK(rtosc_message(buffer, 1024, "/dest", "ifs", i,f,s) == message_size); CHECK(rtosc_argument(buffer, 0).i == i); CHECK(rtosc_argument(buffer, 1).f == f); CHECK(!strcmp(rtosc_argument(buffer, 2).s, s)); CHECK(rtosc_message_length(buffer,1024) == 32); memmove(buffer+1, buffer, message_size); CHECK(!strcmp(buffer+1, "/dest")); CHECK(rtosc_argument(buffer+1, 0).i == i); CHECK(rtosc_argument(buffer+1, 1).f == f); CHECK(!strcmp(rtosc_argument(buffer+1, 2).s, s)); CHECK(rtosc_message_length(buffer+1,1024-1) == 32); memmove(buffer+2, buffer+1, message_size); CHECK(!strcmp(buffer+2, "/dest")); CHECK(rtosc_argument(buffer+2, 0).i == i); CHECK(rtosc_argument(buffer+2, 1).f == f); CHECK(!strcmp(rtosc_argument(buffer+2, 2).s, s)); CHECK(rtosc_message_length(buffer+2,1024-2) == 32); memmove(buffer+3, buffer+2, message_size); CHECK(!strcmp(buffer+3, "/dest")); CHECK(rtosc_argument(buffer+3, 0).i == i); CHECK(rtosc_argument(buffer+3, 1).f == f); CHECK(!strcmp(rtosc_argument(buffer+3, 2).s, s)); CHECK(rtosc_message_length(buffer+3,1024-3) == 32); memmove(buffer+4, buffer+3, message_size); CHECK(!strcmp(buffer+4, "/dest")); CHECK(rtosc_argument(buffer+4, 0).i == i); CHECK(rtosc_argument(buffer+4, 1).f == f); CHECK(!strcmp(rtosc_argument(buffer+4, 2).s, s)); CHECK(rtosc_message_length(buffer+4,1024-4) == 32); for(int j=0; j<4; ++j) { fprintf(stderr, "offset %d\n", j); CHECK(rtosc_argument(buffer+4+j, 0).i == i); CHECK(rtosc_argument(buffer+4+j, 1).f == f); CHECK(!strcmp(rtosc_argument(buffer+4+j, 2).s, s)); CHECK(rtosc_message_length(buffer+4+j,1024-4-j) == (unsigned)(32-j)); } return err; }
void plot_data_cb(const char *msg, void*) { const int samples = rtosc_argument(msg, 0).i; //Construct blob piecewise if(rtosc_message(dsp_osc_buf, 2048, "/ui/plot", "b", samples, NULL)) { //Fill reserved space float *data = (float*) rtosc_argument(dsp_osc_buf,0).b.data; for(int i=0; i < samples; ++i) data[i] = get_sample((float)i/samples); } gui_message(dsp_osc_buf); }
int main() { //clean buffer memset(buffer1, 0xc3, sizeof(buffer1)); //generate liblo message 1 size_t len = 128; lo_message message = lo_message_new(); assert_non_null(message, "Generating A Liblo Message 1 (int/float)", __LINE__); lo_message_add_float(message, 24.0); lo_message_add_int32(message, 42); lo_message_serialise(message, "/path", buffer1, &len); assert_str_eq("/path", buffer1, "Verifying Path From Message 1", __LINE__); assert_f32_eq(24.0f, rtosc_argument(buffer1, 0).f, "Verifying Float From Message 1", __LINE__); assert_int_eq(42, rtosc_argument(buffer1, 1).i, "Verifying Int From Message 1", __LINE__); assert_int_eq(20, rtosc_message_length(buffer1, 128), "Verifying Length From Message 1", __LINE__); //Message 2 size_t len2 = rtosc_message(buffer2, 1024, "/li", "bb", 4, buffer1, 4, buffer1); assert_int_eq(24, len2, "Generate A Rtosc Message 2 (bb)", __LINE__); lo_message msg2 = lo_message_deserialise((void*)buffer2, len2, &result_var); if(assert_non_null(msg2, "Deserialize Message 2 To Liblo", __LINE__)) printf("# Liblo Did Not Accept the Rtosc Message [error '%d']\n", result_var); //Message 3 size_t len3 = rtosc_message(buffer3+4, 2048, "/close-ui", ""); assert_int_eq(16, len3, "Generate A Rtosc Message 3 ()", __LINE__); lo_message msg3 = lo_message_deserialise((void*)(buffer3+4), len3, &result_var); if(assert_non_null(msg2, "Deserialize Message 3 To Liblo", __LINE__)) printf("#Liblo Did Not Accept the Rtosc Message [error '%d']\n", result_var); //Bundle 4 size_t len4 = rtosc_bundle(buffer4, 2048, 0xdeadbeefcafebaad, 3, buffer1, buffer2, buffer3+4); assert_int_eq(88, len4, "Generate A Bundle 4", __LINE__); //Bundle 5 lo_timetag time; time.sec = 0xdeadbeef; time.frac = 0xcafebaad; lo_bundle ms4 = lo_bundle_new(time); lo_bundle_add_message(ms4, "/path", message); lo_bundle_add_message(ms4, "/li", msg2); lo_bundle_add_message(ms4, "/close-ui", msg3); size_t len5 = 2048; lo_bundle_serialise(ms4,(void*)buffer5, &len5); //Verify 4 == 5 assert_non_null(ms4, "Generate A Liblo Bundle 5", __LINE__); assert_hex_eq(buffer5, buffer4, len5, len4, "Verify Liblo Style Bundles", __LINE__); //Cleanup lo_message_free(message); lo_message_free(msg2); lo_message_free(msg3); lo_bundle_free(ms4); return test_summary(); }