Line data Source code
1 : // Copyright 2009 the V8 project authors. All rights reserved.
2 : // Redistribution and use in source and binary forms, with or without
3 : // modification, are permitted provided that the following conditions are
4 : // met:
5 : //
6 : // * Redistributions of source code must retain the above copyright
7 : // notice, this list of conditions and the following disclaimer.
8 : // * Redistributions in binary form must reproduce the above
9 : // copyright notice, this list of conditions and the following
10 : // disclaimer in the documentation and/or other materials provided
11 : // with the distribution.
12 : // * Neither the name of Google Inc. nor the names of its
13 : // contributors may be used to endorse or promote products derived
14 : // from this software without specific prior written permission.
15 : //
16 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 :
28 : #include "src/v8.h"
29 :
30 : #include "src/version.h"
31 : #include "test/cctest/cctest.h"
32 :
33 :
34 : namespace v8 {
35 : namespace internal {
36 :
37 0 : void SetVersion(int major, int minor, int build, int patch,
38 : const char* embedder, bool candidate, const char* soname) {
39 120 : Version::major_ = major;
40 120 : Version::minor_ = minor;
41 120 : Version::build_ = build;
42 120 : Version::patch_ = patch;
43 120 : Version::embedder_ = embedder;
44 120 : Version::candidate_ = candidate;
45 120 : Version::soname_ = soname;
46 0 : }
47 :
48 60 : static void CheckVersion(int major, int minor, int build, int patch,
49 : const char* embedder, bool candidate,
50 : const char* expected_version_string,
51 : const char* expected_generic_soname) {
52 65 : static v8::internal::EmbeddedVector<char, 128> version_str;
53 65 : static v8::internal::EmbeddedVector<char, 128> soname_str;
54 :
55 : // Test version without specific SONAME.
56 : SetVersion(major, minor, build, patch, embedder, candidate, "");
57 60 : Version::GetString(version_str);
58 60 : CHECK_EQ(0, strcmp(expected_version_string, version_str.start()));
59 60 : Version::GetSONAME(soname_str);
60 60 : CHECK_EQ(0, strcmp(expected_generic_soname, soname_str.start()));
61 :
62 : // Test version with specific SONAME.
63 : const char* soname = "libv8.so.1";
64 : SetVersion(major, minor, build, patch, embedder, candidate, soname);
65 60 : Version::GetString(version_str);
66 60 : CHECK_EQ(0, strcmp(expected_version_string, version_str.start()));
67 60 : Version::GetSONAME(soname_str);
68 60 : CHECK_EQ(0, strcmp(soname, soname_str.start()));
69 60 : }
70 :
71 :
72 26644 : TEST(VersionString) {
73 5 : CheckVersion(0, 0, 0, 0, "", false, "0.0.0", "libv8-0.0.0.so");
74 : CheckVersion(0, 0, 0, 0, "", true, "0.0.0 (candidate)",
75 5 : "libv8-0.0.0-candidate.so");
76 5 : CheckVersion(1, 0, 0, 0, "", false, "1.0.0", "libv8-1.0.0.so");
77 : CheckVersion(1, 0, 0, 0, "", true, "1.0.0 (candidate)",
78 5 : "libv8-1.0.0-candidate.so");
79 5 : CheckVersion(1, 0, 0, 1, "", false, "1.0.0.1", "libv8-1.0.0.1.so");
80 : CheckVersion(1, 0, 0, 1, "", true, "1.0.0.1 (candidate)",
81 5 : "libv8-1.0.0.1-candidate.so");
82 5 : CheckVersion(2, 5, 10, 7, "", false, "2.5.10.7", "libv8-2.5.10.7.so");
83 : CheckVersion(2, 5, 10, 7, "", true, "2.5.10.7 (candidate)",
84 5 : "libv8-2.5.10.7-candidate.so");
85 : CheckVersion(6, 0, 287, 0, "-emb.1", false, "6.0.287-emb.1",
86 5 : "libv8-6.0.287-emb.1.so");
87 : CheckVersion(6, 0, 287, 0, "-emb.1", true, "6.0.287-emb.1 (candidate)",
88 5 : "libv8-6.0.287-emb.1-candidate.so");
89 : CheckVersion(6, 0, 287, 53, "-emb.1", false, "6.0.287.53-emb.1",
90 5 : "libv8-6.0.287.53-emb.1.so");
91 : CheckVersion(6, 0, 287, 53, "-emb.1", true, "6.0.287.53-emb.1 (candidate)",
92 5 : "libv8-6.0.287.53-emb.1-candidate.so");
93 5 : }
94 :
95 : } // namespace internal
96 79917 : } // namespace v8
|