OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <stdint.h> |
5 #include <stdio.h> | 6 #include <stdio.h> |
6 | 7 |
7 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 python_command.AppendArgPath(sync_test_script_path); | 48 python_command.AppendArgPath(sync_test_script_path); |
48 if (!base::LaunchProcess(python_command, base::LaunchOptions()).IsValid()) { | 49 if (!base::LaunchProcess(python_command, base::LaunchOptions()).IsValid()) { |
49 LOG(ERROR) << "Failed to launch test script " << sync_test_script_name; | 50 LOG(ERROR) << "Failed to launch test script " << sync_test_script_name; |
50 return false; | 51 return false; |
51 } | 52 } |
52 return true; | 53 return true; |
53 } | 54 } |
54 | 55 |
55 // Gets a port value from the switch with name |switch_name| and writes it to | 56 // Gets a port value from the switch with name |switch_name| and writes it to |
56 // |port|. Returns true if a port was provided and false otherwise. | 57 // |port|. Returns true if a port was provided and false otherwise. |
57 static bool GetPortFromSwitch(const std::string& switch_name, uint16* port) { | 58 static bool GetPortFromSwitch(const std::string& switch_name, uint16_t* port) { |
58 DCHECK(port != NULL) << "|port| is NULL"; | 59 DCHECK(port != NULL) << "|port| is NULL"; |
59 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 60 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
60 int port_int = 0; | 61 int port_int = 0; |
61 if (command_line->HasSwitch(switch_name)) { | 62 if (command_line->HasSwitch(switch_name)) { |
62 std::string port_str = command_line->GetSwitchValueASCII(switch_name); | 63 std::string port_str = command_line->GetSwitchValueASCII(switch_name); |
63 if (!base::StringToInt(port_str, &port_int)) { | 64 if (!base::StringToInt(port_str, &port_int)) { |
64 return false; | 65 return false; |
65 } | 66 } |
66 } | 67 } |
67 *port = static_cast<uint16>(port_int); | 68 *port = static_cast<uint16_t>(port_int); |
68 return true; | 69 return true; |
69 } | 70 } |
70 | 71 |
71 int main(int argc, const char* argv[]) { | 72 int main(int argc, const char* argv[]) { |
72 base::AtExitManager at_exit_manager; | 73 base::AtExitManager at_exit_manager; |
73 base::MessageLoopForIO message_loop; | 74 base::MessageLoopForIO message_loop; |
74 | 75 |
75 // Process command line | 76 // Process command line |
76 base::CommandLine::Init(argc, argv); | 77 base::CommandLine::Init(argc, argv); |
77 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 78 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
(...skipping 14 matching lines...) Expand all Loading... |
92 } | 93 } |
93 | 94 |
94 if (command_line->HasSwitch("sync-test")) { | 95 if (command_line->HasSwitch("sync-test")) { |
95 return RunSyncTest(FILE_PATH_LITERAL("chromiumsync_test.py")) ? 0 : -1; | 96 return RunSyncTest(FILE_PATH_LITERAL("chromiumsync_test.py")) ? 0 : -1; |
96 } | 97 } |
97 | 98 |
98 if (command_line->HasSwitch("xmpp-test")) { | 99 if (command_line->HasSwitch("xmpp-test")) { |
99 return RunSyncTest(FILE_PATH_LITERAL("xmppserver_test.py")) ? 0 : -1; | 100 return RunSyncTest(FILE_PATH_LITERAL("xmppserver_test.py")) ? 0 : -1; |
100 } | 101 } |
101 | 102 |
102 uint16 port = 0; | 103 uint16_t port = 0; |
103 GetPortFromSwitch("port", &port); | 104 GetPortFromSwitch("port", &port); |
104 | 105 |
105 uint16 xmpp_port = 0; | 106 uint16_t xmpp_port = 0; |
106 GetPortFromSwitch("xmpp-port", &xmpp_port); | 107 GetPortFromSwitch("xmpp-port", &xmpp_port); |
107 | 108 |
108 scoped_ptr<syncer::LocalSyncTestServer> test_server( | 109 scoped_ptr<syncer::LocalSyncTestServer> test_server( |
109 new syncer::LocalSyncTestServer(port, xmpp_port)); | 110 new syncer::LocalSyncTestServer(port, xmpp_port)); |
110 if (!test_server->Start()) { | 111 if (!test_server->Start()) { |
111 printf("Error: failed to start python sync test server. Exiting.\n"); | 112 printf("Error: failed to start python sync test server. Exiting.\n"); |
112 return -1; | 113 return -1; |
113 } | 114 } |
114 | 115 |
115 printf("Python sync test server running at %s (type ctrl+c to exit)\n", | 116 printf("Python sync test server running at %s (type ctrl+c to exit)\n", |
116 test_server->host_port_pair().ToString().c_str()); | 117 test_server->host_port_pair().ToString().c_str()); |
117 | 118 |
118 message_loop.Run(); | 119 message_loop.Run(); |
119 return 0; | 120 return 0; |
120 } | 121 } |
OLD | NEW |