1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
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:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #include "session/session_server.h"
31 
32 #include <memory>
33 #include <string>
34 #include <vector>
35 
36 #include "base/scheduler.h"
37 #include "base/system_util.h"
38 #include "testing/base/public/googletest.h"
39 #include "testing/base/public/gunit.h"
40 
41 namespace mozc {
42 namespace {
43 class JobRecorder : public Scheduler::SchedulerInterface {
44  public:
RemoveAllJobs()45   void RemoveAllJobs() {}
RemoveJob(const string & name)46   bool RemoveJob(const string &name) { return true; }
AddJob(const Scheduler::JobSetting & job_setting)47   bool AddJob(const Scheduler::JobSetting &job_setting) {
48     job_settings_.push_back(job_setting);
49     return true;
50   }
HasJob(const string & name) const51   bool HasJob(const string &name) const {
52     for (size_t i = 0; i < job_settings_.size(); ++i) {
53       if (job_settings_[i].name() == name) {
54         return true;
55       }
56     }
57     return false;
58   }
job_settings() const59   const std::vector<Scheduler::JobSetting> &job_settings() const {
60     return job_settings_;
61   }
62 
63  private:
64   std::vector<Scheduler::JobSetting> job_settings_;
65 };
66 }  // namespace
67 class SessionServerTest : public testing::Test {
68  protected:
SetUp()69   void SetUp() {
70     SystemUtil::SetUserProfileDirectory(FLAGS_test_tmpdir);
71   }
72 };
73 
TEST_F(SessionServerTest,SetSchedulerJobTest)74 TEST_F(SessionServerTest, SetSchedulerJobTest) {
75   std::unique_ptr<JobRecorder> job_recorder(new JobRecorder);
76   Scheduler::SetSchedulerHandler(job_recorder.get());
77   std::unique_ptr<SessionServer> session_server(new SessionServer);
78   EXPECT_LE(2, job_recorder->job_settings().size());
79   EXPECT_TRUE(job_recorder->HasJob("UsageStatsTimer"));
80   EXPECT_TRUE(job_recorder->HasJob("SaveCachedStats"));
81   Scheduler::SetSchedulerHandler(NULL);
82 }
83 }  // namespace mozc
84