blob: 8c2d7ba07fbd265d2f7e71d65a0219aba64a6555 [file] [log] [blame]
Dennis Shen1dc9ad42023-05-12 00:21:55 +00001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mårten Kongstadfbd71e22023-05-31 13:29:35 +020017use anyhow::{ensure, Result};
Dennis Shen1dc9ad42023-05-12 00:21:55 +000018use serde::Serialize;
Dennis Shen8d544f72023-06-29 00:45:42 +000019use std::path::PathBuf;
Dennis Shen1dc9ad42023-05-12 00:21:55 +000020use tinytemplate::TinyTemplate;
21
Mårten Kongstadfbd71e22023-05-31 13:29:35 +020022use crate::codegen;
Dennis Shen8d544f72023-06-29 00:45:42 +000023use crate::commands::{CodegenMode, OutputFile};
Mårten Kongstad403658f2023-06-14 09:51:56 +020024use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
Dennis Shen1dc9ad42023-05-12 00:21:55 +000025
Dennis Shen8d544f72023-06-29 00:45:42 +000026pub fn generate_cpp_code<'a, I>(
27 package: &str,
28 parsed_flags_iter: I,
29 codegen_mode: CodegenMode,
30) -> Result<Vec<OutputFile>>
Mårten Kongstad403658f2023-06-14 09:51:56 +020031where
32 I: Iterator<Item = &'a ProtoParsedFlag>,
33{
Mårten Kongstad066575b2023-06-07 16:29:25 +020034 let class_elements: Vec<ClassElement> =
Mårten Kongstad403658f2023-06-14 09:51:56 +020035 parsed_flags_iter.map(|pf| create_class_element(package, pf)).collect();
Dennis Shen1dc9ad42023-05-12 00:21:55 +000036 let readwrite = class_elements.iter().any(|item| item.readwrite);
Mårten Kongstadfbd71e22023-05-31 13:29:35 +020037 let header = package.replace('.', "_");
38 let cpp_namespace = package.replace('.', "::");
39 ensure!(codegen::is_valid_name_ident(&header));
Mårten Kongstad066575b2023-06-07 16:29:25 +020040 let context = Context {
41 header: header.clone(),
42 cpp_namespace,
43 package: package.to_string(),
44 readwrite,
Dennis Shen17a08eec2023-07-14 01:32:50 +000045 for_test: codegen_mode == CodegenMode::Test,
Mårten Kongstad066575b2023-06-07 16:29:25 +020046 class_elements,
47 };
Dennis Shen8d544f72023-06-29 00:45:42 +000048
49 let files = [
50 FileSpec {
51 name: &format!("{}.h", header),
52 template: include_str!("../templates/cpp_exported_header.template"),
53 dir: "include",
54 },
55 FileSpec {
56 name: &format!("{}.cc", header),
57 template: include_str!("../templates/cpp_source_file.template"),
58 dir: "",
59 },
Dennis Shen8d544f72023-06-29 00:45:42 +000060 ];
61 files.iter().map(|file| generate_file(file, &context)).collect()
62}
63
64pub fn generate_file(file: &FileSpec, context: &Context) -> Result<OutputFile> {
Dennis Shen1dc9ad42023-05-12 00:21:55 +000065 let mut template = TinyTemplate::new();
Dennis Shen8d544f72023-06-29 00:45:42 +000066 template.add_template(file.name, file.template)?;
67 let contents = template.render(file.name, &context)?;
68 let path: PathBuf = [&file.dir, &file.name].iter().collect();
Dennis Shen1dc9ad42023-05-12 00:21:55 +000069 Ok(OutputFile { contents: contents.into(), path })
70}
71
72#[derive(Serialize)]
Dennis Shen8d544f72023-06-29 00:45:42 +000073pub struct FileSpec<'a> {
74 pub name: &'a str,
75 pub template: &'a str,
76 pub dir: &'a str,
77}
78
79#[derive(Serialize)]
80pub struct Context {
Mårten Kongstadfbd71e22023-05-31 13:29:35 +020081 pub header: String,
82 pub cpp_namespace: String,
Mårten Kongstad9fb58962023-05-31 13:02:13 +020083 pub package: String,
Dennis Shen1dc9ad42023-05-12 00:21:55 +000084 pub readwrite: bool,
Dennis Shen17a08eec2023-07-14 01:32:50 +000085 pub for_test: bool,
Dennis Shen1dc9ad42023-05-12 00:21:55 +000086 pub class_elements: Vec<ClassElement>,
87}
88
89#[derive(Serialize)]
Dennis Shen8d544f72023-06-29 00:45:42 +000090pub struct ClassElement {
Dennis Shen1dc9ad42023-05-12 00:21:55 +000091 pub readwrite: bool,
92 pub default_value: String,
93 pub flag_name: String,
Mårten Kongstad066575b2023-06-07 16:29:25 +020094 pub device_config_namespace: String,
95 pub device_config_flag: String,
Dennis Shen1dc9ad42023-05-12 00:21:55 +000096}
97
Mårten Kongstad403658f2023-06-14 09:51:56 +020098fn create_class_element(package: &str, pf: &ProtoParsedFlag) -> ClassElement {
Dennis Shen1dc9ad42023-05-12 00:21:55 +000099 ClassElement {
Mårten Kongstad403658f2023-06-14 09:51:56 +0200100 readwrite: pf.permission() == ProtoFlagPermission::READ_WRITE,
101 default_value: if pf.state() == ProtoFlagState::ENABLED {
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000102 "true".to_string()
103 } else {
104 "false".to_string()
105 },
Mårten Kongstad403658f2023-06-14 09:51:56 +0200106 flag_name: pf.name().to_string(),
107 device_config_namespace: pf.namespace().to_string(),
108 device_config_flag: codegen::create_device_config_ident(package, pf.name())
109 .expect("values checked at flag parse time"),
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000110 }
111}
112
113#[cfg(test)]
114mod tests {
115 use super::*;
Dennis Shen8d544f72023-06-29 00:45:42 +0000116 use std::collections::HashMap;
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000117
Dennis Shen8d544f72023-06-29 00:45:42 +0000118 const EXPORTED_PROD_HEADER_EXPECTED: &str = r#"
Dennis Shen5c242132023-07-14 14:57:08 +0000119#pragma once
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000120
Joe Onoratoac692c52023-07-18 17:29:14 -0700121#ifdef __cplusplus
122
Dennis Shen8d544f72023-06-29 00:45:42 +0000123#include <memory>
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000124
Mårten Kongstad403658f2023-06-14 09:51:56 +0200125namespace com::android::aconfig::test {
Dennis Shen8d544f72023-06-29 00:45:42 +0000126class flag_provider_interface {
127public:
Dennis Shen8d544f72023-06-29 00:45:42 +0000128 virtual ~flag_provider_interface() = default;
129
130 virtual bool disabled_ro() = 0;
131
132 virtual bool disabled_rw() = 0;
133
Zhi Dou71f1b352023-08-21 22:49:46 +0000134 virtual bool enabled_fixed_ro() = 0;
135
Dennis Shen8d544f72023-06-29 00:45:42 +0000136 virtual bool enabled_ro() = 0;
137
138 virtual bool enabled_rw() = 0;
Dennis Shen8d544f72023-06-29 00:45:42 +0000139};
140
141extern std::unique_ptr<flag_provider_interface> provider_;
142
Dennis Shen8d544f72023-06-29 00:45:42 +0000143inline bool disabled_ro() {
144 return false;
145}
146
147inline bool disabled_rw() {
148 return provider_->disabled_rw();
149}
150
Zhi Dou71f1b352023-08-21 22:49:46 +0000151inline bool enabled_fixed_ro() {
152 return true;
153}
154
Dennis Shen8d544f72023-06-29 00:45:42 +0000155inline bool enabled_ro() {
156 return true;
157}
158
159inline bool enabled_rw() {
160 return provider_->enabled_rw();
161}
162
Dennis Shen8d544f72023-06-29 00:45:42 +0000163}
Joe Onoratoac692c52023-07-18 17:29:14 -0700164
165extern "C" {
166#endif // __cplusplus
167
168bool com_android_aconfig_test_disabled_ro();
169
170bool com_android_aconfig_test_disabled_rw();
171
Zhi Dou71f1b352023-08-21 22:49:46 +0000172bool com_android_aconfig_test_enabled_fixed_ro();
173
Joe Onoratoac692c52023-07-18 17:29:14 -0700174bool com_android_aconfig_test_enabled_ro();
175
176bool com_android_aconfig_test_enabled_rw();
177
178#ifdef __cplusplus
179} // extern "C"
180#endif
Dennis Shen8d544f72023-06-29 00:45:42 +0000181"#;
182
183 const EXPORTED_TEST_HEADER_EXPECTED: &str = r#"
Dennis Shen5c242132023-07-14 14:57:08 +0000184#pragma once
Dennis Shen8d544f72023-06-29 00:45:42 +0000185
Joe Onoratoac692c52023-07-18 17:29:14 -0700186#ifdef __cplusplus
187
Dennis Shen8d544f72023-06-29 00:45:42 +0000188#include <memory>
Dennis Shen8d544f72023-06-29 00:45:42 +0000189
190namespace com::android::aconfig::test {
Joe Onoratoac692c52023-07-18 17:29:14 -0700191
Dennis Shen8d544f72023-06-29 00:45:42 +0000192class flag_provider_interface {
193public:
194
195 virtual ~flag_provider_interface() = default;
196
197 virtual bool disabled_ro() = 0;
198
Dennis Shen17a08eec2023-07-14 01:32:50 +0000199 virtual void disabled_ro(bool val) = 0;
200
Dennis Shen8d544f72023-06-29 00:45:42 +0000201 virtual bool disabled_rw() = 0;
202
Dennis Shen17a08eec2023-07-14 01:32:50 +0000203 virtual void disabled_rw(bool val) = 0;
204
Zhi Dou71f1b352023-08-21 22:49:46 +0000205 virtual bool enabled_fixed_ro() = 0;
206
207 virtual void enabled_fixed_ro(bool val) = 0;
208
Dennis Shen8d544f72023-06-29 00:45:42 +0000209 virtual bool enabled_ro() = 0;
210
Dennis Shen17a08eec2023-07-14 01:32:50 +0000211 virtual void enabled_ro(bool val) = 0;
212
Dennis Shen8d544f72023-06-29 00:45:42 +0000213 virtual bool enabled_rw() = 0;
214
Dennis Shen17a08eec2023-07-14 01:32:50 +0000215 virtual void enabled_rw(bool val) = 0;
Dennis Shen8d544f72023-06-29 00:45:42 +0000216
Dennis Shen17a08eec2023-07-14 01:32:50 +0000217 virtual void reset_flags() {}
Dennis Shen8d544f72023-06-29 00:45:42 +0000218};
219
220extern std::unique_ptr<flag_provider_interface> provider_;
221
Dennis Shen8d544f72023-06-29 00:45:42 +0000222inline bool disabled_ro() {
223 return provider_->disabled_ro();
224}
225
Dennis Shen17a08eec2023-07-14 01:32:50 +0000226inline void disabled_ro(bool val) {
227 provider_->disabled_ro(val);
228}
229
Dennis Shen8d544f72023-06-29 00:45:42 +0000230inline bool disabled_rw() {
231 return provider_->disabled_rw();
232}
233
Dennis Shen17a08eec2023-07-14 01:32:50 +0000234inline void disabled_rw(bool val) {
235 provider_->disabled_rw(val);
236}
237
Zhi Dou71f1b352023-08-21 22:49:46 +0000238inline bool enabled_fixed_ro() {
239 return provider_->enabled_fixed_ro();
240}
241
242inline void enabled_fixed_ro(bool val) {
243 provider_->enabled_fixed_ro(val);
244}
245
Dennis Shen8d544f72023-06-29 00:45:42 +0000246inline bool enabled_ro() {
247 return provider_->enabled_ro();
248}
249
Dennis Shen17a08eec2023-07-14 01:32:50 +0000250inline void enabled_ro(bool val) {
251 provider_->enabled_ro(val);
252}
253
Dennis Shen8d544f72023-06-29 00:45:42 +0000254inline bool enabled_rw() {
255 return provider_->enabled_rw();
256}
257
Dennis Shen17a08eec2023-07-14 01:32:50 +0000258inline void enabled_rw(bool val) {
259 provider_->enabled_rw(val);
Dennis Shen8d544f72023-06-29 00:45:42 +0000260}
261
Dennis Shen17a08eec2023-07-14 01:32:50 +0000262inline void reset_flags() {
263 return provider_->reset_flags();
Dennis Shen8d544f72023-06-29 00:45:42 +0000264}
265
266}
Dennis Shen8d544f72023-06-29 00:45:42 +0000267
Dennis Shen7321f4f2023-07-11 15:45:00 +0000268extern "C" {
Joe Onoratoac692c52023-07-18 17:29:14 -0700269#endif // __cplusplus
Dennis Shen17a08eec2023-07-14 01:32:50 +0000270
271bool com_android_aconfig_test_disabled_ro();
272
273void set_com_android_aconfig_test_disabled_ro(bool val);
274
275bool com_android_aconfig_test_disabled_rw();
276
277void set_com_android_aconfig_test_disabled_rw(bool val);
278
Zhi Dou71f1b352023-08-21 22:49:46 +0000279bool com_android_aconfig_test_enabled_fixed_ro();
280
281void set_com_android_aconfig_test_enabled_fixed_ro(bool val);
282
Dennis Shen17a08eec2023-07-14 01:32:50 +0000283bool com_android_aconfig_test_enabled_ro();
284
285void set_com_android_aconfig_test_enabled_ro(bool val);
286
287bool com_android_aconfig_test_enabled_rw();
288
289void set_com_android_aconfig_test_enabled_rw(bool val);
290
291void com_android_aconfig_test_reset_flags();
Dennis Shen7321f4f2023-07-11 15:45:00 +0000292
Joe Onoratoac692c52023-07-18 17:29:14 -0700293
Dennis Shen7321f4f2023-07-11 15:45:00 +0000294#ifdef __cplusplus
Joe Onoratoac692c52023-07-18 17:29:14 -0700295} // extern "C"
Dennis Shen7321f4f2023-07-11 15:45:00 +0000296#endif
Joe Onoratoac692c52023-07-18 17:29:14 -0700297
298
Dennis Shen7321f4f2023-07-11 15:45:00 +0000299"#;
300
Joe Onoratoac692c52023-07-18 17:29:14 -0700301 const PROD_SOURCE_FILE_EXPECTED: &str = r#"
Dennis Shen7321f4f2023-07-11 15:45:00 +0000302#include "com_android_aconfig_test.h"
Joe Onoratoac692c52023-07-18 17:29:14 -0700303#include <server_configurable_flags/get_flags.h>
304
305namespace com::android::aconfig::test {
306
307 class flag_provider : public flag_provider_interface {
308 public:
309
310 virtual bool disabled_ro() override {
311 return false;
312 }
313
314 virtual bool disabled_rw() override {
315 return server_configurable_flags::GetServerConfigurableFlag(
Dennis Shenb352b9d2023-08-16 17:33:33 +0000316 "aconfig_flags.aconfig_test",
Joe Onoratoac692c52023-07-18 17:29:14 -0700317 "com.android.aconfig.test.disabled_rw",
318 "false") == "true";
319 }
320
Zhi Dou71f1b352023-08-21 22:49:46 +0000321 virtual bool enabled_fixed_ro() override {
322 return true;
323 }
324
Joe Onoratoac692c52023-07-18 17:29:14 -0700325 virtual bool enabled_ro() override {
326 return true;
327 }
328
329 virtual bool enabled_rw() override {
330 return server_configurable_flags::GetServerConfigurableFlag(
Dennis Shenb352b9d2023-08-16 17:33:33 +0000331 "aconfig_flags.aconfig_test",
Joe Onoratoac692c52023-07-18 17:29:14 -0700332 "com.android.aconfig.test.enabled_rw",
333 "true") == "true";
334 }
335
336 };
337
338 std::unique_ptr<flag_provider_interface> provider_ =
339 std::make_unique<flag_provider>();
340}
Dennis Shen7321f4f2023-07-11 15:45:00 +0000341
342bool com_android_aconfig_test_disabled_ro() {
Dennis Shen5c242132023-07-14 14:57:08 +0000343 return false;
Dennis Shen7321f4f2023-07-11 15:45:00 +0000344}
345
346bool com_android_aconfig_test_disabled_rw() {
347 return com::android::aconfig::test::disabled_rw();
348}
349
Zhi Dou71f1b352023-08-21 22:49:46 +0000350bool com_android_aconfig_test_enabled_fixed_ro() {
351 return true;
352}
353
Dennis Shen7321f4f2023-07-11 15:45:00 +0000354bool com_android_aconfig_test_enabled_ro() {
Dennis Shen5c242132023-07-14 14:57:08 +0000355 return true;
Dennis Shen7321f4f2023-07-11 15:45:00 +0000356}
357
358bool com_android_aconfig_test_enabled_rw() {
359 return com::android::aconfig::test::enabled_rw();
360}
Joe Onoratoac692c52023-07-18 17:29:14 -0700361
Dennis Shen17a08eec2023-07-14 01:32:50 +0000362"#;
Dennis Shen7321f4f2023-07-11 15:45:00 +0000363
Joe Onoratoac692c52023-07-18 17:29:14 -0700364 const TEST_SOURCE_FILE_EXPECTED: &str = r#"
Dennis Shen17a08eec2023-07-14 01:32:50 +0000365#include "com_android_aconfig_test.h"
Joe Onoratoac692c52023-07-18 17:29:14 -0700366#include <server_configurable_flags/get_flags.h>
367
368namespace com::android::aconfig::test {
369
370 class flag_provider : public flag_provider_interface {
371 private:
372 std::unordered_map<std::string, bool> overrides_;
373
374 public:
375 flag_provider()
376 : overrides_()
377 {}
378
379 virtual bool disabled_ro() override {
380 auto it = overrides_.find("disabled_ro");
381 if (it != overrides_.end()) {
382 return it->second;
383 } else {
384 return false;
385 }
386 }
387
388 virtual void disabled_ro(bool val) override {
389 overrides_["disabled_ro"] = val;
390 }
391
392 virtual bool disabled_rw() override {
393 auto it = overrides_.find("disabled_rw");
394 if (it != overrides_.end()) {
395 return it->second;
396 } else {
397 return server_configurable_flags::GetServerConfigurableFlag(
Dennis Shenb352b9d2023-08-16 17:33:33 +0000398 "aconfig_flags.aconfig_test",
Joe Onoratoac692c52023-07-18 17:29:14 -0700399 "com.android.aconfig.test.disabled_rw",
400 "false") == "true";
401 }
402 }
403
404 virtual void disabled_rw(bool val) override {
405 overrides_["disabled_rw"] = val;
406 }
407
Zhi Dou71f1b352023-08-21 22:49:46 +0000408 virtual bool enabled_fixed_ro() override {
409 auto it = overrides_.find("enabled_fixed_ro");
410 if (it != overrides_.end()) {
411 return it->second;
412 } else {
413 return true;
414 }
415 }
416
417 virtual void enabled_fixed_ro(bool val) override {
418 overrides_["enabled_fixed_ro"] = val;
419 }
420
Joe Onoratoac692c52023-07-18 17:29:14 -0700421 virtual bool enabled_ro() override {
422 auto it = overrides_.find("enabled_ro");
423 if (it != overrides_.end()) {
424 return it->second;
425 } else {
426 return true;
427 }
428 }
429
430 virtual void enabled_ro(bool val) override {
431 overrides_["enabled_ro"] = val;
432 }
433
434 virtual bool enabled_rw() override {
435 auto it = overrides_.find("enabled_rw");
436 if (it != overrides_.end()) {
437 return it->second;
438 } else {
439 return server_configurable_flags::GetServerConfigurableFlag(
Dennis Shenb352b9d2023-08-16 17:33:33 +0000440 "aconfig_flags.aconfig_test",
Joe Onoratoac692c52023-07-18 17:29:14 -0700441 "com.android.aconfig.test.enabled_rw",
442 "true") == "true";
443 }
444 }
445
446 virtual void enabled_rw(bool val) override {
447 overrides_["enabled_rw"] = val;
448 }
449
Joe Onoratoac692c52023-07-18 17:29:14 -0700450 virtual void reset_flags() override {
451 overrides_.clear();
452 }
453 };
454
455 std::unique_ptr<flag_provider_interface> provider_ =
456 std::make_unique<flag_provider>();
457}
Dennis Shen17a08eec2023-07-14 01:32:50 +0000458
459bool com_android_aconfig_test_disabled_ro() {
460 return com::android::aconfig::test::disabled_ro();
Dennis Shen7321f4f2023-07-11 15:45:00 +0000461}
462
Joe Onoratoac692c52023-07-18 17:29:14 -0700463
Dennis Shen17a08eec2023-07-14 01:32:50 +0000464void set_com_android_aconfig_test_disabled_ro(bool val) {
465 com::android::aconfig::test::disabled_ro(val);
466}
467
468bool com_android_aconfig_test_disabled_rw() {
469 return com::android::aconfig::test::disabled_rw();
470}
471
Joe Onoratoac692c52023-07-18 17:29:14 -0700472
Dennis Shen17a08eec2023-07-14 01:32:50 +0000473void set_com_android_aconfig_test_disabled_rw(bool val) {
474 com::android::aconfig::test::disabled_rw(val);
475}
476
Zhi Dou71f1b352023-08-21 22:49:46 +0000477
478bool com_android_aconfig_test_enabled_fixed_ro() {
479 return com::android::aconfig::test::enabled_fixed_ro();
480}
481
482void set_com_android_aconfig_test_enabled_fixed_ro(bool val) {
483 com::android::aconfig::test::enabled_fixed_ro(val);
484}
485
486
Dennis Shen17a08eec2023-07-14 01:32:50 +0000487bool com_android_aconfig_test_enabled_ro() {
488 return com::android::aconfig::test::enabled_ro();
489}
490
Joe Onoratoac692c52023-07-18 17:29:14 -0700491
Dennis Shen17a08eec2023-07-14 01:32:50 +0000492void set_com_android_aconfig_test_enabled_ro(bool val) {
493 com::android::aconfig::test::enabled_ro(val);
494}
495
496bool com_android_aconfig_test_enabled_rw() {
497 return com::android::aconfig::test::enabled_rw();
498}
499
Joe Onoratoac692c52023-07-18 17:29:14 -0700500
Dennis Shen17a08eec2023-07-14 01:32:50 +0000501void set_com_android_aconfig_test_enabled_rw(bool val) {
502 com::android::aconfig::test::enabled_rw(val);
503}
504
505void com_android_aconfig_test_reset_flags() {
Joe Onoratoac692c52023-07-18 17:29:14 -0700506 com::android::aconfig::test::reset_flags();
Dennis Shen7321f4f2023-07-11 15:45:00 +0000507}
Joe Onoratoac692c52023-07-18 17:29:14 -0700508
Dennis Shen7321f4f2023-07-11 15:45:00 +0000509"#;
Joe Onoratoac692c52023-07-18 17:29:14 -0700510
Dennis Shen8d544f72023-06-29 00:45:42 +0000511 fn test_generate_cpp_code(mode: CodegenMode) {
512 let parsed_flags = crate::test::parse_test_flags();
513 let generated =
514 generate_cpp_code(crate::test::TEST_PACKAGE, parsed_flags.parsed_flag.iter(), mode)
515 .unwrap();
516 let mut generated_files_map = HashMap::new();
517 for file in generated {
518 generated_files_map.insert(
519 String::from(file.path.to_str().unwrap()),
520 String::from_utf8(file.contents.clone()).unwrap(),
521 );
522 }
523
524 let mut target_file_path = String::from("include/com_android_aconfig_test.h");
525 assert!(generated_files_map.contains_key(&target_file_path));
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000526 assert_eq!(
Mårten Kongstadb0255072023-06-08 10:15:43 +0200527 None,
528 crate::test::first_significant_code_diff(
Dennis Shen8d544f72023-06-29 00:45:42 +0000529 match mode {
530 CodegenMode::Production => EXPORTED_PROD_HEADER_EXPECTED,
531 CodegenMode::Test => EXPORTED_TEST_HEADER_EXPECTED,
532 },
533 generated_files_map.get(&target_file_path).unwrap()
Mårten Kongstadb0255072023-06-08 10:15:43 +0200534 )
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000535 );
Dennis Shen8d544f72023-06-29 00:45:42 +0000536
Dennis Shen8d544f72023-06-29 00:45:42 +0000537 target_file_path = String::from("com_android_aconfig_test.cc");
538 assert!(generated_files_map.contains_key(&target_file_path));
539 assert_eq!(
540 None,
541 crate::test::first_significant_code_diff(
Dennis Shen17a08eec2023-07-14 01:32:50 +0000542 match mode {
Joe Onoratoac692c52023-07-18 17:29:14 -0700543 CodegenMode::Production => PROD_SOURCE_FILE_EXPECTED,
544 CodegenMode::Test => TEST_SOURCE_FILE_EXPECTED,
Dennis Shen17a08eec2023-07-14 01:32:50 +0000545 },
Dennis Shen7321f4f2023-07-11 15:45:00 +0000546 generated_files_map.get(&target_file_path).unwrap()
547 )
548 );
Dennis Shen8d544f72023-06-29 00:45:42 +0000549 }
550
551 #[test]
552 fn test_generate_cpp_code_for_prod() {
553 test_generate_cpp_code(CodegenMode::Production);
554 }
555
556 #[test]
557 fn test_generate_cpp_code_for_test() {
558 test_generate_cpp_code(CodegenMode::Test);
Dennis Shen1dc9ad42023-05-12 00:21:55 +0000559 }
560}