File: ready_string_finder.h

package info (click to toggle)
tango 10.0.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,936 kB
  • sloc: cpp: 201,786; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 272; sql: 72; ruby: 24
file content (47 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef TANGO_TESTS_CATCH2_UTILS_PLATFORM
#define TANGO_TESTS_CATCH2_UTILS_PLATFORM

#include <string>
#include <fstream>

namespace TangoTest::platform
{
class ReadyStringFinder
{
  public:
    /** Searches through the given file for a "ready string" .
     *
     * If the ready string isn't found, the ReadyStringFinder will remember
     * where it is in the file, so that you can try again later once you
     * know there is more data in the file.
     *
     * Example:
     *
     *  ReadyStringFinder finder(my_file);
     *  bool found = false;
     *  do {
     *    if (finder.check_for_ready_string("my ready string")) {
     *      found = true;
     *      break;
     *    }
     *    update_timeout(timeout);
     *  } while(wait_for_new_data(timeout))
     *
     *
     * @param filename -- Path to the file to search
     */
    explicit ReadyStringFinder(const std::string &filename);

    /** Returns true if a line containing the ready_string is found.
     *
     * @param ready_string -- line to search for.
     */
    bool check_for_ready_string(const std::string &ready_string);

  private:
    std::ifstream m_file;
};

} // namespace TangoTest::platform

#endif