llvm/lldb/unittests/Host/XMLTest.cpp

//===-- XMLTest.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Host/XML.h"
#include "gtest/gtest.h"

usingnamespacelldb_private;

#if LLDB_ENABLE_LIBXML2

static void assertGetElement(XMLNode &root, const char *element_name,
                             bool expected_uint_success, uint64_t expected_uint,
                             bool expected_double_success,
                             double expected_double) {}

#define ASSERT_GET(element_name, ...)

TEST(XML, GetAs) {}

#else // !LLDB_ENABLE_LIBXML2

TEST(XML, GracefulNoXML) {
  std::string test_xml =
      "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
      "<test>\n"
      "  <text attribute=\"123\">123</text>\n"
      "</test>\n";

  XMLDocument doc;
  ASSERT_FALSE(doc.ParseMemory(test_xml.data(), test_xml.size()));

  XMLNode root = doc.GetRootElement();
  EXPECT_FALSE(root.IsValid());

  XMLNode node = root.FindFirstChildElementWithName("text");
  EXPECT_FALSE(node.IsValid());

  uint64_t uint_val;
  EXPECT_FALSE(node.GetElementTextAsUnsigned(uint_val, 66, 0));
  EXPECT_EQ(uint_val, 66U);
  EXPECT_FALSE(node.GetAttributeValueAsUnsigned("attribute", uint_val, 66, 0));
  EXPECT_EQ(uint_val, 66U);

  double double_val;
  EXPECT_FALSE(node.GetElementTextAsFloat(double_val, 66.0));
  EXPECT_EQ(double_val, 66.0);
}

#endif // LLDB_ENABLE_LIBXML2