fiber.test.cc (13465:dee578a46d87) | fiber.test.cc (14041:ade853f97d68) |
---|---|
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 21 unchanged lines hidden (view full) --- 30#include <gtest/gtest.h> 31 32#include <initializer_list> 33#include <iostream> 34#include <vector> 35 36#include "base/fiber.hh" 37 | 1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 21 unchanged lines hidden (view full) --- 30#include <gtest/gtest.h> 31 32#include <initializer_list> 33#include <iostream> 34#include <vector> 35 36#include "base/fiber.hh" 37 |
38class TestFiber : public Fiber | 38class SwitchingFiber : public Fiber |
39{ 40 public: 41 const char *name; 42 std::vector<Fiber *> next; 43 | 39{ 40 public: 41 const char *name; 42 std::vector<Fiber *> next; 43 |
44 TestFiber(const char *name, std::initializer_list<Fiber *> l); | 44 SwitchingFiber(const char *name, std::initializer_list<Fiber *> l); |
45 46 void checkExpected(); 47 void main(); 48}; 49 | 45 46 void checkExpected(); 47 void main(); 48}; 49 |
50extern TestFiber a; 51extern TestFiber b; 52extern TestFiber c; | 50extern SwitchingFiber a; 51extern SwitchingFiber b; 52extern SwitchingFiber c; |
53 | 53 |
54TestFiber a("A", { &b, &a, Fiber::primaryFiber(), &b, &c }); 55TestFiber b("B", { &a, &c }); 56TestFiber c("C", { &a, Fiber::primaryFiber(), Fiber::primaryFiber() }); | 54SwitchingFiber a("A", { &b, &a, Fiber::primaryFiber(), &b, &c }); 55SwitchingFiber b("B", { &a, &c }); 56SwitchingFiber c("C", { &a, Fiber::primaryFiber(), Fiber::primaryFiber() }); |
57 | 57 |
58std::vector<TestFiber *>::iterator expectedIt; 59std::vector<TestFiber *> expected({ | 58std::vector<SwitchingFiber *>::iterator expectedIt; 59std::vector<SwitchingFiber *> expected({ |
60 &a, &b, &a, &a, /* main Fiber, */ 61 &a, &b, &c, &a, &c, 62 /* main Fiber, */ &c, &c 63}); 64 | 60 &a, &b, &a, &a, /* main Fiber, */ 61 &a, &b, &c, &a, &c, 62 /* main Fiber, */ &c, &c 63}); 64 |
65TestFiber::TestFiber( | 65SwitchingFiber::SwitchingFiber( |
66 const char *name, std::initializer_list<Fiber *> l) : 67 name(name), next(l) 68{} 69 70void | 66 const char *name, std::initializer_list<Fiber *> l) : 67 name(name), next(l) 68{} 69 70void |
71TestFiber::checkExpected() | 71SwitchingFiber::checkExpected() |
72{ 73 ASSERT_NE(expectedIt, expected.end()); | 72{ 73 ASSERT_NE(expectedIt, expected.end()); |
74 TestFiber *e = *expectedIt++; | 74 SwitchingFiber *e = *expectedIt++; |
75 EXPECT_EQ(e, this) << "Expected " << e->name << ", got " << name; 76} 77 78void | 75 EXPECT_EQ(e, this) << "Expected " << e->name << ", got " << name; 76} 77 78void |
79TestFiber::main() | 79SwitchingFiber::main() |
80{ 81 checkExpected(); 82 for (auto &n : next) { 83 n->run(); 84 checkExpected(); 85 } 86} 87 --- 53 unchanged lines hidden --- | 80{ 81 checkExpected(); 82 for (auto &n : next) { 83 n->run(); 84 checkExpected(); 85 } 86} 87 --- 53 unchanged lines hidden --- |