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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/cloud_print/test_cloud_print_utils.cc
diff --git a/chrome/common/cloud_print/test_cloud_print_utils.cc b/chrome/common/cloud_print/test_cloud_print_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9c8232a2021950deeec77fdefaa456c1df551cc8
--- /dev/null
+++ b/chrome/common/cloud_print/test_cloud_print_utils.cc
@@ -0,0 +1,131 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/cloud_print/test_cloud_print_utils.h"
+
+#include "base/stringprintf.h"
+
+namespace {
+
+const char* kResponseFormat =
+ "{"
+ " \"success\": %s,"
+ " \"%s\": ["
+ "%s"
+ " ]"
+ "}";
+
+const char* kFetchResponseJobFormat =
+ " {"
+ " \"id\": \"job id %s\","
+ " \"tags\": ["
+ " \"__tag1=value_of_tag1\","
+ " \"__tag2=value_of_tag2\""
+ " ]"
+ " }";
+
+const char* kRegistrationResponseFormat =
+ "{"
+ " \"success\": %s,"
+ " \"printers\": [{"
+ " \"id\": \"%s\","
+ " \"name\": \"iPhone Sim\","
+ " \"description\": \"iPhone Sim\","
+ " \"proxy\": \"C112222r918A-1302D05D3\","
+ " \"status\": \"\","
+ " \"capsHash\": \"32d8f876156f15adbb98076\","
+ " \"createTime\": \"134180454\","
+ " \"updateTime\": \"317588454\","
+ " \"accessTime\": \"175880454\","
+ " \"numberOfDocuments\": \"0\","
+ " \"numberOfPages\": \"0\","
+ " \"tags\": ["
+ " \"__apns__device_token=7266850dc25b65d55e\","
+ " \"__apns__package=test.test.test\","
+ " \"__apns__tagshash=b23d5ccdd273c57f8d2a24\","
+ " \"^own\""
+ " ]"
+ " }]"
+ "}";
+
+const char* kListResponsePrinterFormat =
+ " {"
+ " \"id\": \"%s\","
+ " \"name\": \"iPhone Sim\","
+ " \"description\": \"iPhone Sim\","
+ " \"proxy\": \"Chr918A-1302D05D3\","
+ " \"status\": \"\","
+ " \"capsHash\": \"07d26f15adbb98076\","
+ " \"createTime\": \"14175880454\","
+ " \"updateTime\": \"3175880454\","
+ " \"accessTime\": \"11475880454\","
+ " \"numberOfDocuments\": \"0\","
+ " \"numberOfPages\": \"0\","
+ " \"tags\": ["
+ " \"__n__package=test.test.test\","
+ " \"__p__tagshash=b23d5ccd911d14d273c57f8d2a24\","
+ " \"^own\""
+ " ]"
+ " }";
+
+std::string GenerateResponseWithList(bool succeed,
+ const char* list_name,
+ const char* item_format,
+ size_t item_num,
+ va_list items) {
+ std::string list_string;
+
+ const char* current_item = va_arg(items, const char*);
+ for (size_t count = 0; count < item_num; ++count) {
+ if (!list_string.empty())
+ list_string.push_back(',');
+ base::StringAppendF(&list_string, item_format, current_item);
+ current_item = va_arg(items, const char*);
+ }
+
+ return base::StringPrintf(kResponseFormat,
+ succeed ? "true" : "false",
+ list_name,
+ list_string.c_str());
+}
+
+} // namespace
+
+namespace cloud_print{
+
+std::string GenerateFetchSuccessResponseWithJobStrings(size_t job_num ...) {
+ va_list arguments;
+ va_start(arguments, job_num);
+ std::string response_string =
+ GenerateResponseWithList(true, "jobs", "%s", job_num, arguments);
+ va_end(arguments);
+ return response_string;
+}
+
+std::string GenerateFetchSuccessResponseWithJobIds(size_t job_num ...) {
+ va_list arguments;
+ va_start(arguments, job_num);
+ std::string response_string =GenerateResponseWithList(
+ true, "jobs", kFetchResponseJobFormat, job_num, arguments);
+ va_end(arguments);
+ return response_string;
+}
+
+std::string GenerateRegistrationResponse(const bool& succeed,
+ const std::string& printer_id) {
+ return base::StringPrintf(kRegistrationResponseFormat,
+ succeed ? "true" : "false",
+ printer_id.c_str());
+}
+
+std::string GenerateListResponseWithPrinterIds(size_t printer_num ...) {
+ va_list arguments;
+ va_start(arguments, printer_num);
+ std::string response_string =GenerateResponseWithList(
+ true, "printers", kListResponsePrinterFormat, printer_num, arguments);
+ va_end(arguments);
+ return response_string;
+}
+
+} // namespace cloud_print
« 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