Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: terminator_unittest.cc

Issue 5104007: AU: Add unit tests for the Terminator class. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: unnecessary header file Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « terminator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <gtest/gtest.h>
6 #include <gtest/gtest-spi.h>
7
8 #include "update_engine/terminator.h"
9
10 using std::string;
11 using testing::ExitedWithCode;
12
13 namespace chromeos_update_engine {
14
15 class TerminatorTest : public ::testing::Test {
16 protected:
17 virtual void SetUp() {
18 Terminator::Init();
19 ASSERT_FALSE(Terminator::exit_blocked());
20 ASSERT_FALSE(Terminator::exit_requested());
21 }
22 };
23
24 typedef TerminatorTest TerminatorDeathTest;
25
26 namespace {
27 void UnblockExitThroughUnblocker() {
28 ScopedTerminatorExitUnblocker unblocker = ScopedTerminatorExitUnblocker();
29 }
30
31 void RaiseSIGTERM() {
32 ASSERT_EXIT(raise(SIGTERM), ExitedWithCode(0), "");
33 }
34 } // namespace {}
35
36 TEST_F(TerminatorTest, HandleSignalTest) {
37 Terminator::set_exit_blocked(true);
38 Terminator::HandleSignal(SIGTERM);
39 ASSERT_TRUE(Terminator::exit_requested());
40 }
41
42 TEST_F(TerminatorTest, ScopedTerminatorExitUnblockerTest) {
43 Terminator::set_exit_blocked(true);
44 ASSERT_TRUE(Terminator::exit_blocked());
45 ASSERT_FALSE(Terminator::exit_requested());
46 UnblockExitThroughUnblocker();
47 ASSERT_FALSE(Terminator::exit_blocked());
48 ASSERT_FALSE(Terminator::exit_requested());
49 }
50
51 TEST_F(TerminatorDeathTest, ExitTest) {
52 ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(0), "");
53 Terminator::set_exit_blocked(true);
54 ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(0), "");
55 }
56
57 TEST_F(TerminatorDeathTest, RaiseSignalTest) {
58 RaiseSIGTERM();
59 Terminator::set_exit_blocked(true);
60 EXPECT_FATAL_FAILURE(RaiseSIGTERM(), "");
61 }
62
63 TEST_F(TerminatorDeathTest, ScopedTerminatorExitUnblockerExitTest) {
64 Terminator::set_exit_blocked(true);
65 Terminator::exit_requested_ = 1;
66 ASSERT_EXIT(UnblockExitThroughUnblocker(), ExitedWithCode(0), "");
67 }
68
69 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « terminator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698