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
Language: Cpp
Standard: c++14
DerivePointerAlignment: true
SortIncludes: false
ReflowComments: false
PointerAlignment: Left
AlignAfterOpenBracket: AlwaysBreak
AlignOperands: AlignAfterOperator
BreakConstructorInitializers: AfterColon
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
@ -36,3 +38,4 @@ SpaceAfterTemplateKeyword: false
AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: Always
IndentPPDirectives: BeforeHash
Cpp11BracedListStyle: false

20
test/framework.cc

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

4
test/framework.hh

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

22
test/test_adapter_cxx.cc

@ -10,28 +10,33 @@
using namespace pEp::Adapter;
PEP_STATUS messageToSend(struct _message *msg) {
PEP_STATUS messageToSend(struct _message *msg)
{
pEpLog("called");
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");
return PEP_STATUS_OK;
}
class JNISync {
public:
void onSyncStartup() {
void onSyncStartup()
{
pEpLog("called");
}
void onSyncShutdown() {
void onSyncShutdown()
{
pEpLog("called");
}
} o;
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
pEp::Test::setup(argc, argv);
// Create new identity
@ -50,7 +55,12 @@ int main(int argc, char **argv) {
pEpLog(i);
pEpLog("SYNC START");
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");
usleep(sleepuSec);
shutdown();

4
test/test_ensure_passphrase.cc

@ -28,7 +28,8 @@ int main(int argc, char **argv)
passphrase_cache.add("cathy");
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* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
@ -55,4 +56,3 @@ int main(int argc, char **argv)
return 0;
}

22
test/test_leave_device_group.cc

@ -12,21 +12,17 @@ using namespace pEp;
using namespace pEp::Adapter;
using namespace std;
vector<string> expected_msg = {
"synchronizeGroupKeys",
vector<string> expected_msg = { "synchronizeGroupKeys",
"groupKeysUpdate",
"initUnledGroupKeyReset",
"beacon",
"beacon"
};
"beacon" };
vector<::sync_handshake_signal> expected_notification = {
SYNC_NOTIFY_IN_GROUP,
vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_IN_GROUP,
SYNC_NOTIFY_START,
SYNC_NOTIFY_SOLE,
SYNC_NOTIFY_START,
SYNC_NOTIFY_STOP
};
SYNC_NOTIFY_STOP };
PEP_STATUS test_messageToSend(::message* _msg)
{
@ -63,7 +59,8 @@ int main(int argc, char **argv)
passphrase_cache.add("erwin");
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* 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(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);
assert(status == PEP_STATUS_OK);
status = ::enable_identity_for_sync(session(), bob.get());
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);
assert(status == PEP_STATUS_OK);
@ -118,4 +117,3 @@ int main(int argc, char **argv)
return 0;
}

42
test/test_library.cc

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

23
test/test_message_cache.cc

@ -25,7 +25,11 @@ int main(int argc, char **argv)
::message *src = nullptr;
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);
status = ::myself(pEp::Adapter::session(), src->from);
@ -38,7 +42,13 @@ int main(int argc, char **argv)
src->dir = PEP_dir_outgoing;
::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(src->longmsg == nullptr);
@ -69,7 +79,13 @@ int main(int argc, char **argv)
PEP_decrypt_flags_t flags = 0;
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(src->longmsg == nullptr);
@ -95,4 +111,3 @@ int main(int argc, char **argv)
pEp::Adapter::session(pEp::Adapter::release);
return 0;
}

33
test/test_passphrase_cache.cc

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

1
test/test_semaphore.cc

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

Loading…
Cancel
Save