Browse Source

LIB-13: YES, diff breaking cahnge, reformat tests. clang-format now or never!

pull/8/head
heck 4 years ago
parent
commit
9b2defe5fb
  1. 3
      .clang-format
  2. 20
      test/framework.cc
  3. 4
      test/framework.hh
  4. 22
      test/test_adapter_cxx.cc
  5. 4
      test/test_ensure_passphrase.cc
  6. 22
      test/test_leave_device_group.cc
  7. 42
      test/test_library.cc
  8. 23
      test/test_message_cache.cc
  9. 33
      test/test_passphrase_cache.cc
  10. 1
      test/test_semaphore.cc

3
.clang-format

@ -1,11 +1,13 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
Language: Cpp Language: Cpp
Standard: c++14
DerivePointerAlignment: true DerivePointerAlignment: true
SortIncludes: false SortIncludes: false
ReflowComments: false ReflowComments: false
PointerAlignment: Left PointerAlignment: Left
AlignAfterOpenBracket: AlwaysBreak AlignAfterOpenBracket: AlwaysBreak
AlignOperands: AlignAfterOperator AlignOperands: AlignAfterOperator
BreakConstructorInitializers: AfterColon
AlignTrailingComments: true AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false
@ -36,3 +38,4 @@ SpaceAfterTemplateKeyword: false
AccessModifierOffset: -4 AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: Always AllowShortBlocksOnASingleLine: Always
IndentPPDirectives: BeforeHash IndentPPDirectives: BeforeHash
Cpp11BracedListStyle: false

20
test/framework.cc

@ -45,11 +45,9 @@ namespace pEp {
cout << "usage: " << args[0] << " [--dir HOME]" << endl; cout << "usage: " << args[0] << " [--dir HOME]" << endl;
#endif #endif
exit(0); exit(0);
} } else if (args[1] == "--dir" && args.size() == 3) {
else if (args[1] == "--dir" && args.size() == 3) {
dir = args[2]; dir = args[2];
} } else {
else {
cerr << "illegal parameter" << endl; cerr << "illegal parameter" << endl;
exit(1); exit(1);
} }
@ -102,7 +100,11 @@ namespace pEp {
{ {
::message *msg; ::message *msg;
bool has_possible_pEp_msg; bool has_possible_pEp_msg;
PEP_STATUS status = ::mime_decode_message(text.c_str(), text.length(), &msg, &has_possible_pEp_msg); PEP_STATUS status = ::mime_decode_message(
text.c_str(),
text.length(),
&msg,
&has_possible_pEp_msg);
throw_status(status); throw_status(status);
return make_message(msg); return make_message(msg);
} }
@ -143,8 +145,7 @@ namespace pEp {
text += _text; text += _text;
pEp_free(_text); pEp_free(_text);
return text; return text;
} } else if (string("application/pEp.distribution") == a->mime_type) {
else if (string("application/pEp.distribution") == a->mime_type) {
char *_text; char *_text;
status = PER_to_XER_Distribution_msg(a->value, a->size, &_text); status = PER_to_XER_Distribution_msg(a->value, a->size, &_text);
throw_status(status); throw_status(status);
@ -175,7 +176,6 @@ namespace pEp {
void Transport::send(Message msg) void Transport::send(Message msg)
{ {
mkdir(outbox_path.c_str(), 0770); mkdir(outbox_path.c_str(), 0770);
} }
}; }; // namespace Test
}; }; // namespace pEp

4
test/framework.hh

@ -57,7 +57,7 @@ namespace pEp {
extern Transport transport; extern Transport transport;
extern string path; extern string path;
}; }; // namespace Test
}; }; // namespace pEp
#endif // LIBPEPADAPTER_FRAMEWORK_HH #endif // LIBPEPADAPTER_FRAMEWORK_HH

22
test/test_adapter_cxx.cc

@ -10,28 +10,33 @@
using namespace pEp::Adapter; using namespace pEp::Adapter;
PEP_STATUS messageToSend(struct _message *msg) { PEP_STATUS messageToSend(struct _message *msg)
{
pEpLog("called"); pEpLog("called");
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) { PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
{
pEpLog("called"); pEpLog("called");
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
class JNISync { class JNISync {
public: public:
void onSyncStartup() { void onSyncStartup()
{
pEpLog("called"); pEpLog("called");
} }
void onSyncShutdown() { void onSyncShutdown()
{
pEpLog("called"); pEpLog("called");
} }
} o; } o;
int main(int argc, char **argv) { int main(int argc, char **argv)
{
pEp::Test::setup(argc, argv); pEp::Test::setup(argc, argv);
// Create new identity // Create new identity
@ -50,7 +55,12 @@ int main(int argc, char **argv) {
pEpLog(i); pEpLog(i);
pEpLog("SYNC START"); pEpLog("SYNC START");
pEpLog("starting the adapter including sync"); pEpLog("starting the adapter including sync");
startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown); startup<JNISync>(
messageToSend,
notifyHandshake,
&o,
&JNISync::onSyncStartup,
&JNISync::onSyncShutdown);
pEpLog("SYNC STOP"); pEpLog("SYNC STOP");
usleep(sleepuSec); usleep(sleepuSec);
shutdown(); shutdown();

4
test/test_ensure_passphrase.cc

@ -28,7 +28,8 @@ int main(int argc, char **argv)
passphrase_cache.add("cathy"); passphrase_cache.add("cathy");
passphrase_cache.add("bob"); passphrase_cache.add("bob");
const char* bob_filename = ENGINE_TEST "/test_keys/bob-primary-with-password-bob-subkey-without.pgp"; const char* bob_filename = ENGINE_TEST
"/test_keys/bob-primary-with-password-bob-subkey-without.pgp";
const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736"; const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp"; const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
@ -55,4 +56,3 @@ int main(int argc, char **argv)
return 0; return 0;
} }

22
test/test_leave_device_group.cc

@ -12,21 +12,17 @@ using namespace pEp;
using namespace pEp::Adapter; using namespace pEp::Adapter;
using namespace std; using namespace std;
vector<string> expected_msg = { vector<string> expected_msg = { "synchronizeGroupKeys",
"synchronizeGroupKeys",
"groupKeysUpdate", "groupKeysUpdate",
"initUnledGroupKeyReset", "initUnledGroupKeyReset",
"beacon", "beacon",
"beacon" "beacon" };
};
vector<::sync_handshake_signal> expected_notification = { vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_IN_GROUP,
SYNC_NOTIFY_IN_GROUP,
SYNC_NOTIFY_START, SYNC_NOTIFY_START,
SYNC_NOTIFY_SOLE, SYNC_NOTIFY_SOLE,
SYNC_NOTIFY_START, SYNC_NOTIFY_START,
SYNC_NOTIFY_STOP SYNC_NOTIFY_STOP };
};
PEP_STATUS test_messageToSend(::message* _msg) PEP_STATUS test_messageToSend(::message* _msg)
{ {
@ -63,7 +59,8 @@ int main(int argc, char **argv)
passphrase_cache.add("erwin"); passphrase_cache.add("erwin");
passphrase_cache.add("bob"); passphrase_cache.add("bob");
const char* bob_filename = ENGINE_TEST "/test_keys/bob-primary-with-password-bob-subkey-without.pgp"; const char* bob_filename = ENGINE_TEST
"/test_keys/bob-primary-with-password-bob-subkey-without.pgp";
const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736"; const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp"; const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
@ -72,14 +69,16 @@ int main(int argc, char **argv)
Test::import_key_from_file(bob_filename); Test::import_key_from_file(bob_filename);
Test::import_key_from_file(erwin_filename); Test::import_key_from_file(erwin_filename);
Test::Identity bob = Test::make_identity(::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog")); Test::Identity bob = Test::make_identity(
::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog"));
PEP_STATUS status = ::set_own_key(session(), bob.get(), bob_fpr); PEP_STATUS status = ::set_own_key(session(), bob.get(), bob_fpr);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
status = ::enable_identity_for_sync(session(), bob.get()); status = ::enable_identity_for_sync(session(), bob.get());
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
Test::Identity erwin = Test::make_identity(::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin")); Test::Identity erwin = Test::make_identity(
::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin"));
status = ::set_own_key(session(), erwin.get(), erwin_fpr); status = ::set_own_key(session(), erwin.get(), erwin_fpr);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
@ -118,4 +117,3 @@ int main(int argc, char **argv)
return 0; return 0;
} }

42
test/test_library.cc

@ -9,11 +9,9 @@ using namespace pEp;
// Producer's data: // Producer's data:
class P class P {
{
public: public:
P(int i) P(int i) : data{ new char[64] }
: data{new char[64]}
{ {
snprintf(data, 63, "%i", i); snprintf(data, 63, "%i", i);
} }
@ -32,8 +30,7 @@ public:
// Consumer's data: // Consumer's data:
class C class C {
{
public: public:
C(int _i) : i(_i) {} C(int _i) : i(_i) {}
int i; int i;
@ -45,17 +42,12 @@ void consumer_thread()
{ {
bool keep_running = true; bool keep_running = true;
int sum = 0; int sum = 0;
while(keep_running) while (keep_running) {
{ for (auto& q : pc) {
for(auto& q : pc) switch (q.state()) {
{ case PC_State::Created: {
switch(q.state())
{
case PC_State::Created:
{
const int value = atoi(q.pdata->data); const int value = atoi(q.pdata->data);
if(value<0) if (value < 0) {
{
std::cerr << "Q\n"; std::cerr << "Q\n";
keep_running = false; keep_running = false;
} else { } else {
@ -65,15 +57,13 @@ void consumer_thread()
} }
break; break;
} }
case PC_State::Deleted: case PC_State::Deleted: {
{
std::cerr << "D"; std::cerr << "D";
sum -= q.cdata->i; sum -= q.cdata->i;
delete q.cdata; delete q.cdata;
break; break;
} }
case PC_State::Changed: case PC_State::Changed: {
{
std::cerr << "X"; std::cerr << "X";
sum -= q.cdata->i; sum -= q.cdata->i;
delete q.cdata; delete q.cdata;
@ -81,7 +71,8 @@ void consumer_thread()
sum += q.cdata->i; sum += q.cdata->i;
break; break;
} }
default: throw "Illegal state"; default:
throw "Illegal state";
} }
} }
} }
@ -91,20 +82,17 @@ void consumer_thread()
int main() int main()
{ {
for(int i=0; i<10; ++i) for (int i = 0; i < 10; ++i) {
{
pc.insert(new P(i)); pc.insert(new P(i));
} }
std::thread t{ &consumer_thread }; std::thread t{ &consumer_thread };
for(int i=10; i<100; ++i) for (int i = 10; i < 100; ++i) {
{
pc.insert(new P(i)); pc.insert(new P(i));
} }
while( !pc.empty() ) while (!pc.empty()) {
{
auto q = pc.begin(); auto q = pc.begin();
delete q->pdata; delete q->pdata;
pc.erase(q); pc.erase(q);

23
test/test_message_cache.cc

@ -25,7 +25,11 @@ int main(int argc, char **argv)
::message *src = nullptr; ::message *src = nullptr;
bool has_possible_pEp_msg; bool has_possible_pEp_msg;
PEP_STATUS status = MessageCache::cache_mime_decode_message(mime, strlen(mime), &src, &has_possible_pEp_msg); PEP_STATUS status = MessageCache::cache_mime_decode_message(
mime,
strlen(mime),
&src,
&has_possible_pEp_msg);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
status = ::myself(pEp::Adapter::session(), src->from); status = ::myself(pEp::Adapter::session(), src->from);
@ -38,7 +42,13 @@ int main(int argc, char **argv)
src->dir = PEP_dir_outgoing; src->dir = PEP_dir_outgoing;
::message *dst = nullptr; ::message *dst = nullptr;
status = MessageCache::cache_encrypt_message(pEp::Adapter::session(), src, nullptr, &dst, PEP_enc_PEP, 0); status = MessageCache::cache_encrypt_message(
pEp::Adapter::session(),
src,
nullptr,
&dst,
PEP_enc_PEP,
0);
assert(status != PEP_ILLEGAL_VALUE); assert(status != PEP_ILLEGAL_VALUE);
assert(src->longmsg == nullptr); assert(src->longmsg == nullptr);
@ -69,7 +79,13 @@ int main(int argc, char **argv)
PEP_decrypt_flags_t flags = 0; PEP_decrypt_flags_t flags = 0;
stringlist_t *keylist = nullptr; stringlist_t *keylist = nullptr;
status = MessageCache::cache_decrypt_message(pEp::Adapter::session(), src, &dst, &keylist, &rating, &flags); status = MessageCache::cache_decrypt_message(
pEp::Adapter::session(),
src,
&dst,
&keylist,
&rating,
&flags);
assert(status != PEP_ILLEGAL_VALUE); assert(status != PEP_ILLEGAL_VALUE);
assert(src->longmsg == nullptr); assert(src->longmsg == nullptr);
@ -95,4 +111,3 @@ int main(int argc, char **argv)
pEp::Adapter::session(pEp::Adapter::release); pEp::Adapter::session(pEp::Adapter::release);
return 0; return 0;
} }

33
test/test_passphrase_cache.cc

@ -36,15 +36,30 @@ int main(int argc, char **argv)
cache.add("world"); cache.add("world");
std::cout << "expected: two passphrases\n"; std::cout << "expected: two passphrases\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
return false;
});
std::cout << "expected: one passphrase\n"; std::cout << "expected: one passphrase\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return passphrase != "";}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
return passphrase != "";
});
std::cout << "expected: two passphrases but reverse order\n"; std::cout << "expected: two passphrases but reverse order\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
PEP_STATUS status = cache.api(api_test1, pEp::Adapter::session(), "23", bytes, n, (::stringlist_t *) NULL); return false;
});
PEP_STATUS status = cache.api(
api_test1,
pEp::Adapter::session(),
"23",
bytes,
n,
(::stringlist_t *)NULL);
assert(status == PEP_WRONG_PASSPHRASE); assert(status == PEP_WRONG_PASSPHRASE);
status = cache.api(api_test2, pEp::Adapter::session(), n, str, bytes, sl); status = cache.api(api_test2, pEp::Adapter::session(), n, str, bytes, sl);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
@ -57,8 +72,8 @@ int main(int argc, char **argv)
while (1) { while (1) {
std::cout << "'" << _cache.latest_passphrase(_cache) << "'\n"; std::cout << "'" << _cache.latest_passphrase(_cache) << "'\n";
} }
} catch (std::underflow_error &) {
} }
catch (std::underflow_error&) { }
pEp::passphrase_cache.add("hello"); pEp::passphrase_cache.add("hello");
pEp::passphrase_cache.add("world"); pEp::passphrase_cache.add("world");
@ -71,7 +86,10 @@ int main(int argc, char **argv)
sleep(2); sleep(2);
std::cout << "expected: no passphrase\n"; std::cout << "expected: no passphrase\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
return false;
});
status = cache.api(api_test1, pEp::Adapter::session(), str, bytes, n, sl); status = cache.api(api_test1, pEp::Adapter::session(), str, bytes, n, sl);
assert(status == PEP_WRONG_PASSPHRASE); assert(status == PEP_WRONG_PASSPHRASE);
@ -81,4 +99,3 @@ int main(int argc, char **argv)
pEp::Adapter::session(pEp::Adapter::release); pEp::Adapter::session(pEp::Adapter::release);
return 0; return 0;
} }

1
test/test_semaphore.cc

@ -32,4 +32,3 @@ int main()
return 0; return 0;
} }

Loading…
Cancel
Save