TEST_F(FileV4Test, CoreRWTest) { PWScore core; const StringX passkey(L"3rdMambo"); fullItem.SetAttUUID(attItem.GetUUID()); EXPECT_EQ(0U, attItem.GetRefcount()); core.SetPassKey(passkey); core.Execute(AddEntryCommand::Create(&core, fullItem, pws_os::CUUID::NullUUID(), &attItem)); EXPECT_TRUE(core.HasAtt(attItem.GetUUID())); EXPECT_EQ(1U, core.GetAtt(attItem.GetUUID()).GetRefcount()); EXPECT_EQ(PWSfile::SUCCESS, core.WriteFile(fname.c_str(), PWSfile::V40)); core.ClearDBData(); EXPECT_EQ(PWSfile::FAILURE, core.ReadFile(fname.c_str(), L"WrongPassword", true)); EXPECT_EQ(PWSfile::SUCCESS, core.ReadFile(fname.c_str(), passkey, true)); ASSERT_EQ(1, core.GetNumEntries()); ASSERT_EQ(1, core.GetNumAtts()); ASSERT_TRUE(core.Find(fullItem.GetUUID()) != core.GetEntryEndIter()); const CItemData readFullItem = core.GetEntry(core.Find(fullItem.GetUUID())); EXPECT_TRUE(readFullItem.HasAttRef()); EXPECT_EQ(attItem.GetUUID(), readFullItem.GetAttUUID()); EXPECT_EQ(fullItem, readFullItem); ASSERT_TRUE(core.HasAtt(attItem.GetUUID())); EXPECT_EQ(1U, core.GetAtt(attItem.GetUUID()).GetRefcount()); core.Execute(DeleteEntryCommand::Create(&core, readFullItem)); ASSERT_EQ(0, core.GetNumEntries()); ASSERT_EQ(0, core.GetNumAtts()); // Get core to delete any existing commands core.ClearCommands(); }
void print_conflicts(const CompareData &conflicts, const PWScore &core, const PWScore &otherCore, conflict_hdr_func_t hdr_fn, item_diff_func_t diff_fn) { for( const auto &cd: conflicts ) { const CItemData &item = core.Find(cd.uuid0)->second; const CItemData &otherItem = otherCore.Find(cd.uuid1)->second; if (cd.bsDiffs.count() == 1 && cd.bsDiffs.test(CItemData::POLICY) && have_empty_policies(item, otherItem)) continue; hdr_fn(cd, item, otherItem); print_conflicting_item(item, otherItem, cd.bsDiffs, diff_fn); } }
void sbs_print(const PWScore &core, const PWScore &otherCore, const CompareData &matches, const CItemData::FieldBits &comparedFields, unsigned int cols, bool print_fields) { for( const auto &cd: matches ) { const CItemData &item = core.Find(cd.uuid0)->second; const CItemData &otherItem = otherCore.Find(cd.uuid1)->second; if (cd.bsDiffs.count() == 1 && cd.bsDiffs.test(CItemData::POLICY) && have_empty_policies(item, otherItem)) continue; const CItemData::FieldBits &df = cd.bsDiffs.any()? cd.bsDiffs: comparedFields; left_line_t left_line{core, cd.uuid0, cols}; right_line_t right_line{otherCore, cd.uuid1, cols}; wcout << left_line() << L'|' << right_line() << endl; if ( print_fields ) { for( auto ft: diff_fields ) { // print the fields if they were actually found to be different if (df.test(ft) && !have_empty_policies(item, otherItem)) { StringXStream wssl, wssr; wssl << left_line(ft) << flush; wssr << right_line(ft) << flush; lines_vec left_lines{resize_lines(stream2vec(wssl), cols)}, right_lines{resize_lines(stream2vec(wssr), cols)}; const int ndiff = left_lines.size() - right_lines.size(); if (ndiff < 0) left_lines.insert(left_lines.end(), -ndiff, StringX(cols, L' ')); else if (ndiff > 0) right_lines.insert(right_lines.end(), ndiff, StringX(cols, L' ')); for (lines_vec::size_type idx = 0; idx < left_lines.size(); ++idx) wcout << left_lines[idx] << L'|' << right_lines[idx] << endl; } } } wcout << resize(wstring(cols/5, left_line.sep_char), cols) << L'|' << resize(wstring(cols/5, right_line.sep_char), cols) << endl; } };
void print_unique_items(wchar_t tag, const CompareData &cd, const PWScore &core, unique_hdr_func_t hdr_fn) { for(const auto &d: cd) { hdr_fn(d, tag); const CItemData &item = core.Find(d.indatabase == CURRENT? d.uuid0: d.uuid1)->second; for( auto ft : diff_fields ) { switch(ft) { case CItem::GROUP: case CItem::TITLE: case CItem::USER: break; default: if ( d.bsDiffs.test(ft) && !item.GetFieldValue(ft).empty() ) { print_field_value(wcout, tag, item, ft); } } } } }
field_to_line(const PWScore &core, const pws_os::CUUID& uuid, unsigned int cols) : item{core.Find(uuid)->second}, columns{cols} {}