Re: [Vala] How to test async methods?



This is how I am doing, it is not with async mechanism itself, but it
shows how I use MainLoop in testing. I have to ask it to `quit` in
order to unblock.

        public void test_line_receive () {
            bool called = false;
            var loop = new MainLoop ();
            var process = new TestFileProcess ();
            var cut = new AsyncChannel (process);

            cut.on_line_received.connect ((line) => {
                called = true;
                assert (line == "this is the full line received.");
                loop.quit ();
            });

            process.file.write ("this is the full line received.".data);
            process.file.flush ();
            loop.run ();

            assert (called == true);
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]