summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2017-08-08 02:26:49 -0500
committerandroid-build-team Robot2017-08-08 02:26:49 -0500
commit8c26bf4a6fd053ea14f19a59fbdab4c4f201e1b6 (patch)
tree69a749c644ea0b6de7bb72aaad5055729c1c4404
parentd9a98e6a4154098eb76ff302d879d679fe95ff1f (diff)
parent41ca2a824cb5ecf101091bc2212812985c3f0034 (diff)
downloadplatform-system-libvintf-8c26bf4a6fd053ea14f19a59fbdab4c4f201e1b6.tar.gz
platform-system-libvintf-8c26bf4a6fd053ea14f19a59fbdab4c4f201e1b6.tar.xz
platform-system-libvintf-8c26bf4a6fd053ea14f19a59fbdab4c4f201e1b6.zip
release-request-c8b8af6b-4899-402a-9ff7-72255ba5300b-for-git_oc-mr1-release-4253898 snap-temp-L09600000090287887
Change-Id: Ic0149dda2bba986f42267a6f7769c1c688229a62
-rw-r--r--parse_xml.cpp34
-rw-r--r--test/main.cpp22
2 files changed, 54 insertions, 2 deletions
diff --git a/parse_xml.cpp b/parse_xml.cpp
index f12df00..518faec 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -16,10 +16,16 @@
16 16
17// Convert objects from and to xml. 17// Convert objects from and to xml.
18 18
19#define LOG_TAG "libvintf"
20#include <android-base/logging.h>
21
22#include "parse_xml.h"
23
24#include <type_traits>
25
19#include <tinyxml2.h> 26#include <tinyxml2.h>
20 27
21#include "parse_string.h" 28#include "parse_string.h"
22#include "parse_xml.h"
23 29
24namespace android { 30namespace android {
25namespace vintf { 31namespace vintf {
@@ -539,11 +545,35 @@ struct ManifestHalConverter : public XmlNodeConverter<ManifestHal> {
539 std::vector<HalInterface> interfaces; 545 std::vector<HalInterface> interfaces;
540 if (!parseOptionalAttr(root, "format", HalFormat::HIDL, &object->format) || 546 if (!parseOptionalAttr(root, "format", HalFormat::HIDL, &object->format) ||
541 !parseTextElement(root, "name", &object->name) || 547 !parseTextElement(root, "name", &object->name) ||
542 !parseChild(root, transportArchConverter, &object->transportArch) || 548 !parseOptionalChild(root, transportArchConverter, {}, &object->transportArch) ||
543 !parseChildren(root, versionConverter, &object->versions) || 549 !parseChildren(root, versionConverter, &object->versions) ||
544 !parseChildren(root, halInterfaceConverter, &interfaces)) { 550 !parseChildren(root, halInterfaceConverter, &interfaces)) {
545 return false; 551 return false;
546 } 552 }
553
554 switch (object->format) {
555 case HalFormat::HIDL: {
556 if (object->transportArch.empty()) {
557 this->mLastError =
558 "HIDL HAL '" + object->name + "' should have <transport> defined.";
559 return false;
560 }
561 } break;
562 case HalFormat::NATIVE: {
563 if (!object->transportArch.empty()) {
564 this->mLastError =
565 "Native HAL '" + object->name + "' should not have <transport> defined.";
566 return false;
567 }
568 } break;
569 default: {
570 LOG(FATAL) << "Unhandled HalFormat "
571 << static_cast<typename std::underlying_type<HalFormat>::type>(
572 object->format);
573 } break;
574 }
575 if (!object->transportArch.isValid()) return false;
576
547 object->interfaces.clear(); 577 object->interfaces.clear();
548 for (auto &&interface : interfaces) { 578 for (auto &&interface : interfaces) {
549 auto res = object->interfaces.emplace(interface.name, 579 auto res = object->interfaces.emplace(interface.name,
diff --git a/test/main.cpp b/test/main.cpp
index 8dc5ddb..42932e5 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -304,6 +304,28 @@ TEST_F(LibVintfTest, HalManifestOptional) {
304 "</manifest>")); 304 "</manifest>"));
305} 305}
306 306
307TEST_F(LibVintfTest, HalManifestNative) {
308 HalManifest vm;
309 EXPECT_TRUE(gHalManifestConverter(&vm,
310 "<manifest version=\"1.0\" type=\"device\">"
311 " <hal format=\"native\">"
312 " <name>foo</name>"
313 " <version>1.0</version>"
314 " </hal>"
315 "</manifest>"))
316 << gHalManifestConverter.lastError();
317 EXPECT_FALSE(gHalManifestConverter(&vm,
318 "<manifest version=\"1.0\" type=\"device\">"
319 " <hal format=\"native\">"
320 " <name>foo</name>"
321 " <version>1.0</version>"
322 " <transport>hwbinder</transport>"
323 " </hal>"
324 "</manifest>"));
325 EXPECT_TRUE(gHalManifestConverter.lastError().find(
326 "Native HAL 'foo' should not have <transport> defined") != std::string::npos);
327}
328
307TEST_F(LibVintfTest, HalManifestDuplicate) { 329TEST_F(LibVintfTest, HalManifestDuplicate) {
308 HalManifest vm; 330 HalManifest vm;
309 EXPECT_FALSE(gHalManifestConverter(&vm, 331 EXPECT_FALSE(gHalManifestConverter(&vm,