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

Side by Side Diff: chrome/common/cloud_print/test_cloud_print_utils.cc

Issue 11038063: Support chrome_to_mobile job receiving Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix format Created 8 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 | « chrome/common/cloud_print/test_cloud_print_utils.h ('k') | chrome/common/pref_names.h » ('j') | 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 2012 The Chromium 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 "chrome/common/cloud_print/test_cloud_print_utils.h"
6
7 #include "base/stringprintf.h"
8
9 namespace {
10
11 const char* kResponseFormat =
12 "{"
13 " \"success\": %s,"
14 " \"%s\": ["
15 "%s"
16 " ]"
17 "}";
18
19 const char* kFetchResponseJobFormat =
20 " {"
21 " \"id\": \"job id %s\","
22 " \"tags\": ["
23 " \"__tag1=value_of_tag1\","
24 " \"__tag2=value_of_tag2\""
25 " ]"
26 " }";
27
28 const char* kRegistrationResponseFormat =
29 "{"
30 " \"success\": %s,"
31 " \"printers\": [{"
32 " \"id\": \"%s\","
33 " \"name\": \"iPhone Sim\","
34 " \"description\": \"iPhone Sim\","
35 " \"proxy\": \"C112222r918A-1302D05D3\","
36 " \"status\": \"\","
37 " \"capsHash\": \"32d8f876156f15adbb98076\","
38 " \"createTime\": \"134180454\","
39 " \"updateTime\": \"317588454\","
40 " \"accessTime\": \"175880454\","
41 " \"numberOfDocuments\": \"0\","
42 " \"numberOfPages\": \"0\","
43 " \"tags\": ["
44 " \"__apns__device_token=7266850dc25b65d55e\","
45 " \"__apns__package=test.test.test\","
46 " \"__apns__tagshash=b23d5ccdd273c57f8d2a24\","
47 " \"^own\""
48 " ]"
49 " }]"
50 "}";
51
52 const char* kListResponsePrinterFormat =
53 " {"
54 " \"id\": \"%s\","
55 " \"name\": \"iPhone Sim\","
56 " \"description\": \"iPhone Sim\","
57 " \"proxy\": \"Chr918A-1302D05D3\","
58 " \"status\": \"\","
59 " \"capsHash\": \"07d26f15adbb98076\","
60 " \"createTime\": \"14175880454\","
61 " \"updateTime\": \"3175880454\","
62 " \"accessTime\": \"11475880454\","
63 " \"numberOfDocuments\": \"0\","
64 " \"numberOfPages\": \"0\","
65 " \"tags\": ["
66 " \"__n__package=test.test.test\","
67 " \"__p__tagshash=b23d5ccd911d14d273c57f8d2a24\","
68 " \"^own\""
69 " ]"
70 " }";
71
72 std::string GenerateResponseWithList(bool succeed,
73 const char* list_name,
74 const char* item_format,
75 size_t item_num,
76 va_list items) {
77 std::string list_string;
78
79 const char* current_item = va_arg(items, const char*);
80 for (size_t count = 0; count < item_num; ++count) {
81 if (!list_string.empty())
82 list_string.push_back(',');
83 base::StringAppendF(&list_string, item_format, current_item);
84 current_item = va_arg(items, const char*);
85 }
86
87 return base::StringPrintf(kResponseFormat,
88 succeed ? "true" : "false",
89 list_name,
90 list_string.c_str());
91 }
92
93 } // namespace
94
95 namespace cloud_print{
96
97 std::string GenerateFetchSuccessResponseWithJobStrings(size_t job_num ...) {
98 va_list arguments;
99 va_start(arguments, job_num);
100 std::string response_string =
101 GenerateResponseWithList(true, "jobs", "%s", job_num, arguments);
102 va_end(arguments);
103 return response_string;
104 }
105
106 std::string GenerateFetchSuccessResponseWithJobIds(size_t job_num ...) {
107 va_list arguments;
108 va_start(arguments, job_num);
109 std::string response_string =GenerateResponseWithList(
110 true, "jobs", kFetchResponseJobFormat, job_num, arguments);
111 va_end(arguments);
112 return response_string;
113 }
114
115 std::string GenerateRegistrationResponse(const bool& succeed,
116 const std::string& printer_id) {
117 return base::StringPrintf(kRegistrationResponseFormat,
118 succeed ? "true" : "false",
119 printer_id.c_str());
120 }
121
122 std::string GenerateListResponseWithPrinterIds(size_t printer_num ...) {
123 va_list arguments;
124 va_start(arguments, printer_num);
125 std::string response_string =GenerateResponseWithList(
126 true, "printers", kListResponsePrinterFormat, printer_num, arguments);
127 va_end(arguments);
128 return response_string;
129 }
130
131 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/common/cloud_print/test_cloud_print_utils.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698