/* prepare ordinary wander record block (fill all service fields) */ static void format_wander_record(struct commit_handle *ch, jnode *node, __u32 serial) { struct wander_record_header *LRH; jnode *next; assert("zam-464", node != NULL); LRH = (struct wander_record_header *)jdata(node); next = list_entry(node->capture_link.next, jnode, capture_link); if (&ch->tx_list == &next->capture_link) next = list_entry(ch->tx_list.next, jnode, capture_link); assert("zam-465", LRH != NULL); assert("zam-463", ch->super->s_blocksize > sizeof(struct wander_record_header)); memset(jdata(node), 0, (size_t) ch->super->s_blocksize); memcpy(jdata(node), WANDER_RECORD_MAGIC, WANDER_RECORD_MAGIC_SIZE); put_unaligned(cpu_to_le32(ch->tx_size), &LRH->total); put_unaligned(cpu_to_le32(serial), &LRH->serial); put_unaligned(cpu_to_le64(*jnode_get_block(next)), &LRH->next_block); }
/* Fill first wander record (tx head) in accordance with supplied given data */ static void format_tx_head(struct commit_handle *ch) { jnode *tx_head; jnode *next; struct tx_header *header; tx_head = list_entry(ch->tx_list.next, jnode, capture_link); assert("zam-692", &ch->tx_list != &tx_head->capture_link); next = list_entry(tx_head->capture_link.next, jnode, capture_link); if (&ch->tx_list == &next->capture_link) next = tx_head; header = (struct tx_header *)jdata(tx_head); assert("zam-460", header != NULL); assert("zam-462", ch->super->s_blocksize >= sizeof(struct tx_header)); memset(jdata(tx_head), 0, (size_t) ch->super->s_blocksize); memcpy(jdata(tx_head), TX_HEADER_MAGIC, TX_HEADER_MAGIC_SIZE); put_unaligned(cpu_to_le32(ch->tx_size), &header->total); put_unaligned(cpu_to_le64(get_super_private(ch->super)->last_committed_tx), &header->prev_tx); put_unaligned(cpu_to_le64(*jnode_get_block(next)), &header->next_block); put_unaligned(cpu_to_le64(ch->free_blocks), &header->free_blocks); put_unaligned(cpu_to_le64(ch->nr_files), &header->nr_files); put_unaligned(cpu_to_le64(ch->next_oid), &header->next_oid); }
/* fill journal footer block data */ static void format_journal_footer(struct commit_handle *ch) { struct reiser4_super_info_data *sbinfo; struct journal_footer *footer; jnode *tx_head; sbinfo = get_super_private(ch->super); tx_head = list_entry(ch->tx_list.next, jnode, capture_link); assert("zam-493", sbinfo != NULL); assert("zam-494", sbinfo->journal_header != NULL); check_me("zam-691", jload(sbinfo->journal_footer) == 0); footer = (struct journal_footer *)jdata(sbinfo->journal_footer); assert("zam-495", footer != NULL); put_unaligned(cpu_to_le64(*jnode_get_block(tx_head)), &footer->last_flushed_tx); put_unaligned(cpu_to_le64(ch->free_blocks), &footer->free_blocks); put_unaligned(cpu_to_le64(ch->nr_files), &footer->nr_files); put_unaligned(cpu_to_le64(ch->next_oid), &footer->next_oid); jrelse(sbinfo->journal_footer); }
TEST(ioJson,jsonData_scalar_real) { std::string txt = "{ \"foo\" : 1.1 }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<double> expected_vals; expected_vals.push_back(1.1); std::vector<size_t> expected_dims; test_real_var(jdata,txt,"foo",expected_vals,expected_dims); }
// parser only reads one top-level object TEST(ioJson,jsonData_parse_mult_objects) { std::string txt = "{ \"foo\": 1}{ \"bar\": 1 }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<std::string> var_names; jdata.names_i(var_names); EXPECT_EQ(1U,var_names.size()); EXPECT_EQ("foo",var_names[0]); }
TEST(ioJson,jsonData_parse_empty_obj) { std::string txt = "{}"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<std::string> var_names; jdata.names_r(var_names); EXPECT_EQ(0U,var_names.size()); jdata.names_i(var_names); EXPECT_EQ(0U,var_names.size()); }
void test_exception(const std::string& input, const std::string& exception_text) { try { std::stringstream s(input); stan::json::json_data jdata(s); } catch (const std::exception& e) { EXPECT_EQ(e.what(), exception_text); return; } FAIL(); // didn't throw an exception as expected. }
TEST(ioJson,jsonData_array_1D_neg_inf) { std::string txt = "{ \"foo\" : [ 1.1, \"-inf\" ] }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<double> expected_vals; expected_vals.push_back(1.1); expected_vals.push_back(-std::numeric_limits<double>::infinity()); std::vector<size_t> expected_dims; expected_dims.push_back(2); test_real_var(jdata,txt,"foo",expected_vals,expected_dims); }
TEST(ioJson,jsonData_real_array_1D) { std::string txt = "{ \"foo\" : [ 1.1, 2.2 ] }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<double> expected_vals; expected_vals.push_back(1.1); expected_vals.push_back(2.2); std::vector<size_t> expected_dims; expected_dims.push_back(2); test_real_var(jdata,txt,"foo",expected_vals,expected_dims); }
TEST(ioJson,jsonData_mult_vars2) { std::string txt = "{ \"foo\" : \"-inf\", \"bar\" : 0.1 }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<double> expected_vals_r; expected_vals_r.push_back(-std::numeric_limits<double>::infinity()); std::vector<size_t> expected_dims; test_real_var(jdata,txt,"foo",expected_vals_r,expected_dims); expected_vals_r.clear(); expected_vals_r.push_back(0.1); test_real_var(jdata,txt,"bar",expected_vals_r,expected_dims); }
TEST(ioJson,jsonData_mult_vars) { std::string txt = "{ \"foo\" : 1, \"bar\" : 0.1 }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<int> expected_vals_i; expected_vals_i.push_back(1); std::vector<size_t> expected_dims; test_int_var(jdata,txt,"foo",expected_vals_i,expected_dims); std::vector<double> expected_vals_r; expected_vals_r.push_back(0.1); test_real_var(jdata,txt,"bar",expected_vals_r,expected_dims); }
/* add one wandered map entry to formatted wander record */ static void store_entry(jnode * node, int index, const reiser4_block_nr * a, const reiser4_block_nr * b) { char *data; struct wander_entry *pairs; data = jdata(node); assert("zam-451", data != NULL); pairs = (struct wander_entry *)(data + sizeof(struct wander_record_header)); put_unaligned(cpu_to_le64(*a), &pairs[index].original); put_unaligned(cpu_to_le64(*b), &pairs[index].wandered); }
void GUICore::WSDataReceived(int ID, std::string data) { auto d = clients.find(ID); if (d == clients.end()) { EXTinvalidParameter("WS-dataReceived: NoClient found. ID: " + std::to_string(ID) + " Data: " + data); } clientData *cd = clients.at(ID); JStruct jdata(data); if (jdata["type"] == "call") { this->callFromClient(jdata["node"].getValue(), (jdata.contains("id") ? jdata["id"].getValue() : ""), ID, (jdata.contains("data") ? jdata["data"].getValue() : ""), cd->sessionID); if (streq(jdata["node"].getValue(), usermanagement::commandInfo::logout())) { cd->sessionID = ""; } } else if (jdata["type"] == "hook") this->hookFromClient(jdata["node"].getValue(), ID, cd->sessionID); else if (jdata["type"] == "unhook") { //Remove hook from ID's Events list for (std::vector<std::string>::iterator i = cd->clientHooks.begin(); i != cd->clientHooks.end(); i++) { if (*i == jdata["node"].getValue()) { cd->clientHooks.erase(i); break; } } //Check to see if there are no more events of this kind, if so, send unHook to server, int counter = 0; for (std::map<int, clientData *>::iterator iter = clients.begin(); iter != clients.end(); iter++) { for (std::vector<std::string>::iterator i = iter->second->clientHooks.begin(); i != iter->second->clientHooks.end(); i++) { if (*i == jdata["node"].getValue()) { counter++; }//todo:: wat if there is a err while unhooking from _core? } } if (counter == 0) guiCHI->sm.communication.removeHook(jdata["node"].getValue()); return; } }
/* fill journal header block data */ static void format_journal_header(struct commit_handle *ch) { struct reiser4_super_info_data *sbinfo; struct journal_header *header; jnode *txhead; sbinfo = get_super_private(ch->super); assert("zam-479", sbinfo != NULL); assert("zam-480", sbinfo->journal_header != NULL); txhead = list_entry(ch->tx_list.next, jnode, capture_link); jload(sbinfo->journal_header); header = (struct journal_header *)jdata(sbinfo->journal_header); assert("zam-484", header != NULL); put_unaligned(cpu_to_le64(*jnode_get_block(txhead)), &header->last_committed_tx); jrelse(sbinfo->journal_header); }
TEST(ioJson,jsonData_int_array_3D) { std::string txt = "{ \"foo\" : [ [ [ 111, 112, 113, 114 ], [ 121, 122, 123, 124 ], [ 131, 132, 133, 134] ]," " [ [ 211, 212, 213, 214 ], [ 221, 222, 223, 224 ], [ 231, 232, 233, 234] ] ] }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<int> expected_vals; expected_vals.push_back(111); expected_vals.push_back(211); expected_vals.push_back(121); expected_vals.push_back(221); expected_vals.push_back(131); expected_vals.push_back(231); expected_vals.push_back(112); expected_vals.push_back(212); expected_vals.push_back(122); expected_vals.push_back(222); expected_vals.push_back(132); expected_vals.push_back(232); expected_vals.push_back(113); expected_vals.push_back(213); expected_vals.push_back(123); expected_vals.push_back(223); expected_vals.push_back(133); expected_vals.push_back(233); expected_vals.push_back(114); expected_vals.push_back(214); expected_vals.push_back(124); expected_vals.push_back(224); expected_vals.push_back(134); expected_vals.push_back(234); std::vector<size_t> expected_dims; expected_dims.push_back(2); // two rows expected_dims.push_back(3); // three cols expected_dims.push_back(4); // four shelves test_int_var(jdata,txt,"foo",expected_vals,expected_dims); }
TEST(ioJson,jsonData_real_array_3D) { std::string txt = "{ \"foo\" : [ [ [ 11.1, 11.2, 11.3, 11.4 ], [ 12.1, 12.2, 12.3, 12.4 ], [ 13.1, 13.2, 13.3, 13.4] ]," " [ [ 21.1, 21.2, 21.3, 21.4 ], [ 22.1, 22.2, 22.3, 22.4 ], [ 23.1, 23.2, 23.3, 23.4] ] ] }"; std::stringstream in(txt); stan::json::json_data jdata(in); std::vector<double> expected_vals; expected_vals.push_back(11.1); expected_vals.push_back(21.1); expected_vals.push_back(12.1); expected_vals.push_back(22.1); expected_vals.push_back(13.1); expected_vals.push_back(23.1); expected_vals.push_back(11.2); expected_vals.push_back(21.2); expected_vals.push_back(12.2); expected_vals.push_back(22.2); expected_vals.push_back(13.2); expected_vals.push_back(23.2); expected_vals.push_back(11.3); expected_vals.push_back(21.3); expected_vals.push_back(12.3); expected_vals.push_back(22.3); expected_vals.push_back(13.3); expected_vals.push_back(23.3); expected_vals.push_back(11.4); expected_vals.push_back(21.4); expected_vals.push_back(12.4); expected_vals.push_back(22.4); expected_vals.push_back(13.4); expected_vals.push_back(23.4); std::vector<size_t> expected_dims; expected_dims.push_back(2); // two rows expected_dims.push_back(3); // three cols expected_dims.push_back(4); // four shelves test_real_var(jdata,txt,"foo",expected_vals,expected_dims); }