a19644ffa05fb5da9d6883ad049fe465c1021dfe
[WebKit-https.git] / Source / JavaScriptCore / replay / scripts / tests / expected / generate-enums-with-same-base-name.json-TestReplayInputs.cpp
1 /*
2  * Copyright (C) 2014 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
15  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 // DO NOT EDIT THIS FILE. It is automatically generated from generate-enums-with-same-base-name.json
28 // by the script: JavaScriptCore/replay/scripts/CodeGeneratorReplayInputs.py
29
30 #include "config.h"
31 #include "generate-enums-with-same-base-name.json-TestReplayInputs.h"
32
33 #if ENABLE(WEB_REPLAY)
34 #include "InternalNamespaceImplIncludeDummy.h"
35 #include <platform/ExternalNamespaceImplIncludeDummy.h>
36
37 namespace Test {
38 FormCombo::FormCombo(PlatformEvent1::Type eventType1, PlatformEvent2::Type eventType2, FormData1::Type formType1, FormData2::Type formType2)
39     : NondeterministicInput<FormCombo>()
40     , m_eventType1(eventType1)
41     , m_eventType2(eventType2)
42     , m_formType1(formType1)
43     , m_formType2(formType2)
44 {
45 }
46
47 FormCombo::~FormCombo()
48 {
49 }
50 } // namespace Test
51
52 namespace JSC {
53 const String& InputTraits<Test::FormCombo>::type()
54 {
55     static NeverDestroyed<const String> type(ASCIILiteral("FormCombo"));
56     return type;
57 }
58
59 void InputTraits<Test::FormCombo>::encode(EncodedValue& encodedValue, const Test::FormCombo& input)
60 {
61     encodedValue.put<PlatformEvent1::Type>(ASCIILiteral("eventType1"), input.eventType1());
62     encodedValue.put<PlatformEvent2::Type>(ASCIILiteral("eventType2"), input.eventType2());
63     encodedValue.put<Test::FormData1::Type>(ASCIILiteral("formType1"), input.formType1());
64     encodedValue.put<Test::FormData2::Type>(ASCIILiteral("formType2"), input.formType2());
65 }
66
67 bool InputTraits<Test::FormCombo>::decode(EncodedValue& encodedValue, std::unique_ptr<Test::FormCombo>& input)
68 {
69     PlatformEvent1::Type eventType1;
70     if (!encodedValue.get<PlatformEvent1::Type>(ASCIILiteral("eventType1"), eventType1))
71         return false;
72
73     PlatformEvent2::Type eventType2;
74     if (!encodedValue.get<PlatformEvent2::Type>(ASCIILiteral("eventType2"), eventType2))
75         return false;
76
77     Test::FormData1::Type formType1;
78     if (!encodedValue.get<Test::FormData1::Type>(ASCIILiteral("formType1"), formType1))
79         return false;
80
81     Test::FormData2::Type formType2;
82     if (!encodedValue.get<Test::FormData2::Type>(ASCIILiteral("formType2"), formType2))
83         return false;
84
85     input = std::make_unique<Test::FormCombo>(eventType1, eventType2, formType1, formType2);
86     return true;
87 }
88 EncodedValue EncodingTraits<Test::FormData1::Type>::encodeValue(const Test::FormData1::Type& enumValue)
89 {
90     EncodedValue encodedValue = EncodedValue::createArray();
91     if (enumValue & Test::FormData1::Text) {
92         encodedValue.append<String>(ASCIILiteral("Text"));
93         if (enumValue == Test::FormData1::Text)
94             return encodedValue;
95     }
96     if (enumValue & Test::FormData1::Blob) {
97         encodedValue.append<String>(ASCIILiteral("Blob"));
98         if (enumValue == Test::FormData1::Blob)
99             return encodedValue;
100     }
101     return encodedValue;
102 }
103
104 bool EncodingTraits<Test::FormData1::Type>::decodeValue(EncodedValue& encodedValue, Test::FormData1::Type& enumValue)
105 {
106     Vector<String> enumStrings;
107     if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
108         return false;
109
110     for (const String& enumString : enumStrings) {
111         if (enumString == "Text")
112             enumValue = static_cast<Test::FormData1::Type>(enumValue | Test::FormData1::Text);
113         else if (enumString == "Blob")
114             enumValue = static_cast<Test::FormData1::Type>(enumValue | Test::FormData1::Blob);
115     }
116
117     return true;
118 }
119
120 EncodedValue EncodingTraits<Test::FormData2::Type>::encodeValue(const Test::FormData2::Type& enumValue)
121 {
122     switch (enumValue) {
123     case Test::FormData2::Type::Text: return EncodedValue::createString("Text");
124     case Test::FormData2::Type::Blob: return EncodedValue::createString("Blob");
125     default: ASSERT_NOT_REACHED(); return EncodedValue::createString("Error!");
126     }
127 }
128
129 bool EncodingTraits<Test::FormData2::Type>::decodeValue(EncodedValue& encodedValue, Test::FormData2::Type& enumValue)
130 {
131     String enumString = encodedValue.convertTo<String>();
132     if (enumString == "Text") {
133         enumValue = Test::FormData2::Type::Text;
134         return true;
135     }
136     if (enumString == "Blob") {
137         enumValue = Test::FormData2::Type::Blob;
138         return true;
139     }
140     return false;
141 }
142 } // namespace JSC
143
144 #endif // ENABLE(WEB_REPLAY)