Skip to content

Commit

Permalink
Add c++ test using lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
hu55a1n1 committed Apr 4, 2018
1 parent c39c614 commit 92eb1a0
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions testscpp.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
//
// Created by Shoaib Ahmed on 3/30/18.
//
#include <vector>
#include <iostream>
#include <chrono>
#include <thread>
#include "libdo.h"

static int runs;

bool cb(void *param) {
(void) param;
return true;
}

bool predicate(void *param) {
(void) param;
return (runs++ % 2) == 0;
}
static int run_after_iterations = 5;

int main() {
int iterations = 0;
auto d = do_init();
auto dw = do_work_when(cb, nullptr, predicate);
if (!d) {
exit(EXIT_FAILURE);
}

auto dw = do_work_when(
// Cannot capture, use void data ptr instead
[](void *data) {
std::cout << "> Work ran after " << *reinterpret_cast<int *>(data) << " iterations" << std::endl;
return true;
},
&iterations,
[](void *data) {
return (*reinterpret_cast<int *>(data)) >= run_after_iterations;
}
);
if (!dw) {
do_destroy(d);
exit(EXIT_FAILURE);
}

std::cout << "--- Work will run after " << run_after_iterations << " iterations ---" << std::endl;
do_so(d, dw);
while (do_loop(d));
return 0;
while (do_loop(d)) {
iterations++;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
do_destroy(d);
exit(EXIT_SUCCESS);
}

0 comments on commit 92eb1a0

Please sign in to comment.