summaryrefslogtreecommitdiffstats
path: root/o3d/utils/cross
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-17 13:21:07 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-17 13:21:07 +0000
commita0abcf44533e242c524ed2955838880d00feadc9 (patch)
treea2e15f339acf72930b63122040e6fdaace0f1e70 /o3d/utils/cross
parent1f01d47474d6b06a2d1351416eeed320f892dde2 (diff)
downloadchromium_src-a0abcf44533e242c524ed2955838880d00feadc9.zip
chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.tar.gz
chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.tar.bz2
Add missing gclient dependencies to .gitignore.
Fix the format of many directories so they don't show up in git status anymore. Run dos2unix on *.cc, caught many inconsistent and CRLF files. TBR=evan TEST=still build, git status shows nothing BUG=none Review URL: http://codereview.chromium.org/211010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/utils/cross')
-rw-r--r--o3d/utils/cross/base64_test.cc340
-rw-r--r--o3d/utils/cross/dataurl.cc226
-rw-r--r--o3d/utils/cross/math_gtest.cc238
-rw-r--r--o3d/utils/cross/math_gtest_test.cc140
4 files changed, 472 insertions, 472 deletions
diff --git a/o3d/utils/cross/base64_test.cc b/o3d/utils/cross/base64_test.cc
index 9eacd69..d291f14 100644
--- a/o3d/utils/cross/base64_test.cc
+++ b/o3d/utils/cross/base64_test.cc
@@ -1,170 +1,170 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file contains the tests of base64 functions
-
-#include "tests/common/win/testing_common.h"
-#include "utils/cross/base64.h"
-
-namespace o3d {
-
-class Base64Test : public testing::Test {
-};
-
-TEST_F(Base64Test, GetEncodeLength) {
- EXPECT_EQ(0u, base64::GetEncodeLength(0));
- EXPECT_EQ(4u, base64::GetEncodeLength(1));
- EXPECT_EQ(4u, base64::GetEncodeLength(2));
- EXPECT_EQ(4u, base64::GetEncodeLength(3));
- EXPECT_EQ(8u, base64::GetEncodeLength(4));
-}
-
-TEST_F(Base64Test, Encode) {
- unsigned char buffer[100];
- memset(buffer, 0xFF, sizeof(buffer));
- base64::Encode("abc", 3, buffer);
- EXPECT_EQ(0, memcmp(buffer, "YWJj", 4));
- EXPECT_EQ(0xFF, buffer[4]);
- memset(buffer, 0xFF, sizeof(buffer));
- base64::Encode("ab\0c", 4, buffer);
- EXPECT_EQ(0, memcmp(buffer, "YWIAYw==", 8));
- EXPECT_EQ(0xFF, buffer[8]);
-}
-
-TEST_F(Base64Test, GetDecodeLength) {
- size_t length = 256u;
- base64::GetDecodeLength("", 0, &length);
- EXPECT_EQ(0u, length);
-
- length = 256u;
- base64::GetDecodeLength("YQ==", 4, &length);
- EXPECT_EQ(1u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWI=", 4, &length);
- EXPECT_EQ(2u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWJj", 4, &length);
- EXPECT_EQ(3u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWJjZA==", 8, &length);
- EXPECT_EQ(4u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWJjZGU=", 8, &length);
- EXPECT_EQ(5u, length);
-}
-
-TEST_F(Base64Test, GetDecodeLengthInputError) {
- base64::DecodeStatus status = base64::kSuccess;
- size_t length = 256u;
- status = base64::GetDecodeLength("Y@==", 4, &length);
- EXPECT_EQ(base64::kBadCharError, status);
-
- status = base64::GetDecodeLength("Y Q==", 4, &length);
- EXPECT_EQ(base64::kSuccess, status);
-
- status = base64::GetDecodeLength("Y", 1, &length);
- EXPECT_EQ(base64::kPadError, status);
-}
-
-TEST_F(Base64Test, Decode) {
- unsigned char buffer[10];
- memset(buffer, 0xFF, sizeof(buffer));
- unsigned char result_buffer[10];
- memset(result_buffer, 0xFF, sizeof(result_buffer));
- base64::DecodeStatus status = base64::kSuccess;
-
- status = base64::Decode("", 0, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[0] = 'a';
- status = base64::Decode("YQ==", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[1] = 'b';
- status = base64::Decode("YWI=", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[2] = 'c';
- status = base64::Decode("YWJj", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[3] = 'd';
- status = base64::Decode("YWJjZA==", 8, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[4] = 'e';
- status = base64::Decode("YWJjZGU=", 8, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-}
-
-TEST_F(Base64Test, DecodeInputError) {
- unsigned char buffer[10];
- base64::DecodeStatus status = base64::kSuccess;
- status = base64::Decode("Y@==", 4, buffer, 10);
- EXPECT_EQ(base64::kBadCharError, status);
-
- status = base64::Decode("Y Q==", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
-
- status = base64::Decode("Y", 1, buffer, 10);
- EXPECT_EQ(base64::kPadError, status);
-}
-
-TEST_F(Base64Test, DecodeOverflowError) {
- unsigned char buffer[10];
- base64::DecodeStatus status = base64::kSuccess;
- status = base64::Decode("YWJjZA==", 8, buffer, 3);
- EXPECT_EQ(base64::kOutputOverflowError, status);
-
- status = base64::Decode("YWJjZA==", 8, buffer, 4);
- EXPECT_EQ(base64::kSuccess, status);
-
- status = base64::Decode("YQ==", 8, buffer, 0);
- EXPECT_EQ(base64::kOutputOverflowError, status);
-
- status = base64::Decode("YQ==", 8, buffer, 1);
- EXPECT_EQ(base64::kSuccess, status);
-}
-
-} // namespace o3d
-
-
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// This file contains the tests of base64 functions
+
+#include "tests/common/win/testing_common.h"
+#include "utils/cross/base64.h"
+
+namespace o3d {
+
+class Base64Test : public testing::Test {
+};
+
+TEST_F(Base64Test, GetEncodeLength) {
+ EXPECT_EQ(0u, base64::GetEncodeLength(0));
+ EXPECT_EQ(4u, base64::GetEncodeLength(1));
+ EXPECT_EQ(4u, base64::GetEncodeLength(2));
+ EXPECT_EQ(4u, base64::GetEncodeLength(3));
+ EXPECT_EQ(8u, base64::GetEncodeLength(4));
+}
+
+TEST_F(Base64Test, Encode) {
+ unsigned char buffer[100];
+ memset(buffer, 0xFF, sizeof(buffer));
+ base64::Encode("abc", 3, buffer);
+ EXPECT_EQ(0, memcmp(buffer, "YWJj", 4));
+ EXPECT_EQ(0xFF, buffer[4]);
+ memset(buffer, 0xFF, sizeof(buffer));
+ base64::Encode("ab\0c", 4, buffer);
+ EXPECT_EQ(0, memcmp(buffer, "YWIAYw==", 8));
+ EXPECT_EQ(0xFF, buffer[8]);
+}
+
+TEST_F(Base64Test, GetDecodeLength) {
+ size_t length = 256u;
+ base64::GetDecodeLength("", 0, &length);
+ EXPECT_EQ(0u, length);
+
+ length = 256u;
+ base64::GetDecodeLength("YQ==", 4, &length);
+ EXPECT_EQ(1u, length);
+
+ length = 256u;
+ base64::GetDecodeLength("YWI=", 4, &length);
+ EXPECT_EQ(2u, length);
+
+ length = 256u;
+ base64::GetDecodeLength("YWJj", 4, &length);
+ EXPECT_EQ(3u, length);
+
+ length = 256u;
+ base64::GetDecodeLength("YWJjZA==", 8, &length);
+ EXPECT_EQ(4u, length);
+
+ length = 256u;
+ base64::GetDecodeLength("YWJjZGU=", 8, &length);
+ EXPECT_EQ(5u, length);
+}
+
+TEST_F(Base64Test, GetDecodeLengthInputError) {
+ base64::DecodeStatus status = base64::kSuccess;
+ size_t length = 256u;
+ status = base64::GetDecodeLength("Y@==", 4, &length);
+ EXPECT_EQ(base64::kBadCharError, status);
+
+ status = base64::GetDecodeLength("Y Q==", 4, &length);
+ EXPECT_EQ(base64::kSuccess, status);
+
+ status = base64::GetDecodeLength("Y", 1, &length);
+ EXPECT_EQ(base64::kPadError, status);
+}
+
+TEST_F(Base64Test, Decode) {
+ unsigned char buffer[10];
+ memset(buffer, 0xFF, sizeof(buffer));
+ unsigned char result_buffer[10];
+ memset(result_buffer, 0xFF, sizeof(result_buffer));
+ base64::DecodeStatus status = base64::kSuccess;
+
+ status = base64::Decode("", 0, buffer, 10);
+ EXPECT_EQ(base64::kSuccess, status);
+ EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
+
+ result_buffer[0] = 'a';
+ status = base64::Decode("YQ==", 4, buffer, 10);
+ EXPECT_EQ(base64::kSuccess, status);
+ EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
+
+ result_buffer[1] = 'b';
+ status = base64::Decode("YWI=", 4, buffer, 10);
+ EXPECT_EQ(base64::kSuccess, status);
+ EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
+
+ result_buffer[2] = 'c';
+ status = base64::Decode("YWJj", 4, buffer, 10);
+ EXPECT_EQ(base64::kSuccess, status);
+ EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
+
+ result_buffer[3] = 'd';
+ status = base64::Decode("YWJjZA==", 8, buffer, 10);
+ EXPECT_EQ(base64::kSuccess, status);
+ EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
+
+ result_buffer[4] = 'e';
+ status = base64::Decode("YWJjZGU=", 8, buffer, 10);
+ EXPECT_EQ(base64::kSuccess, status);
+ EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
+}
+
+TEST_F(Base64Test, DecodeInputError) {
+ unsigned char buffer[10];
+ base64::DecodeStatus status = base64::kSuccess;
+ status = base64::Decode("Y@==", 4, buffer, 10);
+ EXPECT_EQ(base64::kBadCharError, status);
+
+ status = base64::Decode("Y Q==", 4, buffer, 10);
+ EXPECT_EQ(base64::kSuccess, status);
+
+ status = base64::Decode("Y", 1, buffer, 10);
+ EXPECT_EQ(base64::kPadError, status);
+}
+
+TEST_F(Base64Test, DecodeOverflowError) {
+ unsigned char buffer[10];
+ base64::DecodeStatus status = base64::kSuccess;
+ status = base64::Decode("YWJjZA==", 8, buffer, 3);
+ EXPECT_EQ(base64::kOutputOverflowError, status);
+
+ status = base64::Decode("YWJjZA==", 8, buffer, 4);
+ EXPECT_EQ(base64::kSuccess, status);
+
+ status = base64::Decode("YQ==", 8, buffer, 0);
+ EXPECT_EQ(base64::kOutputOverflowError, status);
+
+ status = base64::Decode("YQ==", 8, buffer, 1);
+ EXPECT_EQ(base64::kSuccess, status);
+}
+
+} // namespace o3d
+
+
diff --git a/o3d/utils/cross/dataurl.cc b/o3d/utils/cross/dataurl.cc
index f796719..328d174 100644
--- a/o3d/utils/cross/dataurl.cc
+++ b/o3d/utils/cross/dataurl.cc
@@ -1,113 +1,113 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// This file contains the definition of functions for dealing with data urls.
-
-#include "utils/cross/dataurl.h"
-#include "core/cross/types.h"
-#include "utils/cross/base64.h"
-
-namespace o3d {
-namespace dataurl {
-
-const char* const kEmptyDataURL = "data:,";
-
-String ToDataURL(const String& mime_type, const void* data, size_t length) {
- String header(String("data:") + mime_type + ";base64,");
- String result(header.size() + base64::GetEncodeLength(length), ' ');
- result.replace(0, header.size(), header);
- base64::Encode(data, length, &result[header.size()]);
- return result;
-}
-
-// Decodes the data URL and stores a pointer to the data in dst_buffer
-bool FromDataURL(const String& data_url,
- scoped_array<uint8>* dst_buffer,
- size_t* output_length,
- String* error_string) {
- // First parse the data_url
- const String kDataHeader("data:");
- const String kBase64Header(";base64,");
- // The string has to be long enough.
- if (data_url.size() <= kDataHeader.size() + kBase64Header.size()) {
- *error_string = "Invalid formatting: The data URL is not long enough.";
- return false;
- }
- // it must start with "data:"
- if (data_url.compare(0, kDataHeader.size(), kDataHeader) != 0) {
- *error_string
- = "Invalid formatting: The data URL must start with 'data:'";
- return false;
- }
- // we only support base64 data URL's
- String::size_type data_index = data_url.find(kBase64Header);
- if (data_index == String::npos) {
- *error_string
- = "Invalid formatting: The data URL have ';base64,' in the header.";
- return false;
- }
- // The start of the data.
- data_index += kBase64Header.size();
- if (data_index >= data_url.size()) {
- *error_string
- = "Invalid formatting: There must be data in the body of the data URL.";
- return false;
- }
-
- // Get the length of the decoded data
- size_t input_length = data_url.size() - data_index;
- base64::DecodeStatus return_code = base64::GetDecodeLength(
- &data_url[data_index],
- input_length,
- output_length);
- if (return_code != base64::kSuccess) {
- if (return_code == base64::kPadError) {
- *error_string
- = "Invalid formatting: Padding error in the data URL data.";
- } else {
- *error_string
- = "Invalid formatting: Bad character error in the data URL data.";
- }
- return false;
- }
-
- dst_buffer->reset(new uint8[*output_length]);
- base64::Decode(&data_url[data_index],
- input_length,
- dst_buffer->get(),
- (*output_length));
-
- return true;
-}
-
-} // namespace dataurl
-} // namespace o3d
-
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// This file contains the definition of functions for dealing with data urls.
+
+#include "utils/cross/dataurl.h"
+#include "core/cross/types.h"
+#include "utils/cross/base64.h"
+
+namespace o3d {
+namespace dataurl {
+
+const char* const kEmptyDataURL = "data:,";
+
+String ToDataURL(const String& mime_type, const void* data, size_t length) {
+ String header(String("data:") + mime_type + ";base64,");
+ String result(header.size() + base64::GetEncodeLength(length), ' ');
+ result.replace(0, header.size(), header);
+ base64::Encode(data, length, &result[header.size()]);
+ return result;
+}
+
+// Decodes the data URL and stores a pointer to the data in dst_buffer
+bool FromDataURL(const String& data_url,
+ scoped_array<uint8>* dst_buffer,
+ size_t* output_length,
+ String* error_string) {
+ // First parse the data_url
+ const String kDataHeader("data:");
+ const String kBase64Header(";base64,");
+ // The string has to be long enough.
+ if (data_url.size() <= kDataHeader.size() + kBase64Header.size()) {
+ *error_string = "Invalid formatting: The data URL is not long enough.";
+ return false;
+ }
+ // it must start with "data:"
+ if (data_url.compare(0, kDataHeader.size(), kDataHeader) != 0) {
+ *error_string
+ = "Invalid formatting: The data URL must start with 'data:'";
+ return false;
+ }
+ // we only support base64 data URL's
+ String::size_type data_index = data_url.find(kBase64Header);
+ if (data_index == String::npos) {
+ *error_string
+ = "Invalid formatting: The data URL have ';base64,' in the header.";
+ return false;
+ }
+ // The start of the data.
+ data_index += kBase64Header.size();
+ if (data_index >= data_url.size()) {
+ *error_string
+ = "Invalid formatting: There must be data in the body of the data URL.";
+ return false;
+ }
+
+ // Get the length of the decoded data
+ size_t input_length = data_url.size() - data_index;
+ base64::DecodeStatus return_code = base64::GetDecodeLength(
+ &data_url[data_index],
+ input_length,
+ output_length);
+ if (return_code != base64::kSuccess) {
+ if (return_code == base64::kPadError) {
+ *error_string
+ = "Invalid formatting: Padding error in the data URL data.";
+ } else {
+ *error_string
+ = "Invalid formatting: Bad character error in the data URL data.";
+ }
+ return false;
+ }
+
+ dst_buffer->reset(new uint8[*output_length]);
+ base64::Decode(&data_url[data_index],
+ input_length,
+ dst_buffer->get(),
+ (*output_length));
+
+ return true;
+}
+
+} // namespace dataurl
+} // namespace o3d
+
diff --git a/o3d/utils/cross/math_gtest.cc b/o3d/utils/cross/math_gtest.cc
index 0f7cc90d..1296817 100644
--- a/o3d/utils/cross/math_gtest.cc
+++ b/o3d/utils/cross/math_gtest.cc
@@ -1,119 +1,119 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// This file defines the some helper for gtest for the math library used by O3D.
-
-#include "utils/cross/math_gtest.h"
-#include "core/cross/types.h"
-
-
-namespace Vectormath {
-namespace Aos {
-
-bool operator==(const Vector4& left, const Vector4& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
- left[3] == right[3];
-}
-
-bool operator!=(const Vector4& left, const Vector4& right) {
- return !(left == right);
-}
-
-bool operator==(const Matrix4& left, const Matrix4& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
- left[3] == right[3];
-}
-
-bool operator!=(const Matrix4& left, const Matrix4& right) {
- return !(left == right);
-}
-
-std::ostream& operator<<(std::ostream& stream, const Vector4& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
- << value[3] << "}";
- return stream;
-}
-
-std::ostream& operator<<(std::ostream& stream, const Matrix4& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
- << value[3] << "}";
- return stream;
-}
-
-} // namespace Aos
-} // namespace Vectormath
-
-namespace o3d {
-
-bool operator==(const Float2& left, const Float2& right) {
- return left[0] == right[0] && left[1] == right[1];
-}
-
-bool operator!=(const Float2& left, const Float2& right) {
- return !(left == right);
-}
-
-bool operator==(const Float3& left, const Float3& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2];
-}
-
-bool operator!=(const Float3& left, const Float3& right) {
- return !(left == right);
-}
-
-bool operator==(const Float4& left, const Float4& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
- left[3] == right[3];
-}
-
-bool operator!=(const Float4& left, const Float4& right) {
- return !(left == right);
-}
-
-std::ostream& operator<<(std::ostream& stream, const Float2& value) {
- stream << "{" << value[0] << ", " << value[1] << "}";
- return stream;
-}
-
-std::ostream& operator<<(std::ostream& stream, const Float3& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << "}";
- return stream;
-}
-
-std::ostream& operator<<(std::ostream& stream, const Float4& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
- << value[3] << "}";
- return stream;
-}
-
-} // namespace o3d
-
-
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// This file defines the some helper for gtest for the math library used by O3D.
+
+#include "utils/cross/math_gtest.h"
+#include "core/cross/types.h"
+
+
+namespace Vectormath {
+namespace Aos {
+
+bool operator==(const Vector4& left, const Vector4& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
+ left[3] == right[3];
+}
+
+bool operator!=(const Vector4& left, const Vector4& right) {
+ return !(left == right);
+}
+
+bool operator==(const Matrix4& left, const Matrix4& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
+ left[3] == right[3];
+}
+
+bool operator!=(const Matrix4& left, const Matrix4& right) {
+ return !(left == right);
+}
+
+std::ostream& operator<<(std::ostream& stream, const Vector4& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
+ << value[3] << "}";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Matrix4& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
+ << value[3] << "}";
+ return stream;
+}
+
+} // namespace Aos
+} // namespace Vectormath
+
+namespace o3d {
+
+bool operator==(const Float2& left, const Float2& right) {
+ return left[0] == right[0] && left[1] == right[1];
+}
+
+bool operator!=(const Float2& left, const Float2& right) {
+ return !(left == right);
+}
+
+bool operator==(const Float3& left, const Float3& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2];
+}
+
+bool operator!=(const Float3& left, const Float3& right) {
+ return !(left == right);
+}
+
+bool operator==(const Float4& left, const Float4& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
+ left[3] == right[3];
+}
+
+bool operator!=(const Float4& left, const Float4& right) {
+ return !(left == right);
+}
+
+std::ostream& operator<<(std::ostream& stream, const Float2& value) {
+ stream << "{" << value[0] << ", " << value[1] << "}";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Float3& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << "}";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Float4& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
+ << value[3] << "}";
+ return stream;
+}
+
+} // namespace o3d
+
+
diff --git a/o3d/utils/cross/math_gtest_test.cc b/o3d/utils/cross/math_gtest_test.cc
index a0e4f00..ae6bc62 100644
--- a/o3d/utils/cross/math_gtest_test.cc
+++ b/o3d/utils/cross/math_gtest_test.cc
@@ -1,70 +1,70 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "utils/cross/math_gtest.h"
-
-namespace o3d {
-
-class MathGTestTest : public testing::Test {
-};
-
-// Test the math gtest helper functions.
-TEST_F(MathGTestTest, TestMathGTest) {
- EXPECT_EQ(Float2(1.2f, 2.3f), Float2(1.2f, 2.3f));
- EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.3f, 2.3f));
- EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.2f, 2.4f));
- EXPECT_EQ(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.5f));
- EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.3f, 2.3f, 4.5f));
- EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.4f, 4.5f));
- EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.6f));
- EXPECT_EQ(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.3f, 2.3f, 4.5f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.4f, 4.5f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.6f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.8f));
- Matrix4 a(Vector4(1.1f, 2.2f, 3.3f, 4.4f),
- Vector4(1.2f, 2.3f, 3.4f, 4.5f),
- Vector4(1.3f, 2.4f, 3.5f, 4.6f),
- Vector4(1.4f, 2.5f, 3.6f, 4.7f));
- Matrix4 b(a);
- EXPECT_EQ(a, b);
- for (int ii = 0; ii < 4; ++ii) {
- for (int jj = 0; jj < 4; ++jj) {
- b = a;
- b.setElem(ii, jj, b.getElem(ii, jj) * 2);
- EXPECT_NE(a, b);
- }
- }
-}
-
-} // namespace o3d
-
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests/common/win/testing_common.h"
+#include "utils/cross/math_gtest.h"
+
+namespace o3d {
+
+class MathGTestTest : public testing::Test {
+};
+
+// Test the math gtest helper functions.
+TEST_F(MathGTestTest, TestMathGTest) {
+ EXPECT_EQ(Float2(1.2f, 2.3f), Float2(1.2f, 2.3f));
+ EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.3f, 2.3f));
+ EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.2f, 2.4f));
+ EXPECT_EQ(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.5f));
+ EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.3f, 2.3f, 4.5f));
+ EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.4f, 4.5f));
+ EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.6f));
+ EXPECT_EQ(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.3f, 2.3f, 4.5f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.4f, 4.5f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.6f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.8f));
+ Matrix4 a(Vector4(1.1f, 2.2f, 3.3f, 4.4f),
+ Vector4(1.2f, 2.3f, 3.4f, 4.5f),
+ Vector4(1.3f, 2.4f, 3.5f, 4.6f),
+ Vector4(1.4f, 2.5f, 3.6f, 4.7f));
+ Matrix4 b(a);
+ EXPECT_EQ(a, b);
+ for (int ii = 0; ii < 4; ++ii) {
+ for (int jj = 0; jj < 4; ++jj) {
+ b = a;
+ b.setElem(ii, jj, b.getElem(ii, jj) * 2);
+ EXPECT_NE(a, b);
+ }
+ }
+}
+
+} // namespace o3d
+