attribute.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2011 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // Author: jdtang@google.com (Jonathan Tang)
  16. #include "attribute.h"
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "gtest/gtest.h"
  20. #include "test_utils.h"
  21. #include "vector.h"
  22. namespace {
  23. class GumboAttributeTest : public GumboTest {
  24. protected:
  25. GumboAttributeTest() { gumbo_vector_init(&parser_, 2, &vector_); }
  26. ~GumboAttributeTest() { gumbo_vector_destroy(&parser_, &vector_); }
  27. GumboVector vector_;
  28. };
  29. TEST_F(GumboAttributeTest, GetAttribute) {
  30. GumboAttribute attr1;
  31. GumboAttribute attr2;
  32. attr1.name = "";
  33. attr2.name = "foo";
  34. gumbo_vector_add(&parser_, &attr1, &vector_);
  35. gumbo_vector_add(&parser_, &attr2, &vector_);
  36. EXPECT_EQ(&attr2, gumbo_get_attribute(&vector_, "foo"));
  37. EXPECT_EQ(NULL, gumbo_get_attribute(&vector_, "bar"));
  38. }
  39. } // namespace