#include <string>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/test/test_timeouts.h"
#include "codelabs/cpp101/solutions/services/math/math_service.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/remote.h"
int main(int argc, char* argv[]) {
base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
TestTimeouts::Initialize();
base::test::TaskEnvironment task_environment{
base::test::TaskEnvironment::TimeSource::SYSTEM_TIME};
mojo::core::Init();
if (argc < 3) {
LOG(INFO) << argv[0] << ": missing operand";
return -1;
}
int dividend = 0;
if (!base::StringToInt(argv[1], ÷nd)) {
LOG(INFO) << argv[0] << ": invalid dividend '" << argv[1] << "'";
return -1;
}
int divisor = 0;
if (!base::StringToInt(argv[2], &divisor) || divisor == 0) {
LOG(INFO) << argv[0] << ": invalid divisor '" << argv[2] << "'";
return -1;
}
mojo::Remote<math::mojom::MathService> math_service;
math::MathService math_service_impl(
math_service.BindNewPipeAndPassReceiver());
base::test::TestFuture<int32_t> future;
math_service->Divide(dividend, divisor, future.GetCallback());
int32_t quotient = future.Get();
LOG(INFO) << "Quotient: " << quotient;
return 0;
}