1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/EnumeratedArray.h"
9 using mozilla::EnumeratedArray
;
11 enum class AnimalSpecies
{ Cow
, Sheep
, Pig
, Count
};
13 using TestArray
= EnumeratedArray
<AnimalSpecies
, AnimalSpecies::Count
, int>;
15 void TestInitialValueByConstructor() {
17 TestArray
headCount(1, 2, 3);
18 MOZ_RELEASE_ASSERT(headCount
[AnimalSpecies::Cow
] == 1);
19 MOZ_RELEASE_ASSERT(headCount
[AnimalSpecies::Sheep
] == 2);
20 MOZ_RELEASE_ASSERT(headCount
[AnimalSpecies::Pig
] == 3);
22 TestArray headCount2
{5, 6, 7};
23 MOZ_RELEASE_ASSERT(headCount2
[AnimalSpecies::Cow
] == 5);
24 MOZ_RELEASE_ASSERT(headCount2
[AnimalSpecies::Sheep
] == 6);
25 MOZ_RELEASE_ASSERT(headCount2
[AnimalSpecies::Pig
] == 7);
27 TestArray
headCount3({8, 9, 10});
28 MOZ_RELEASE_ASSERT(headCount3
[AnimalSpecies::Cow
] == 8);
29 MOZ_RELEASE_ASSERT(headCount3
[AnimalSpecies::Sheep
] == 9);
30 MOZ_RELEASE_ASSERT(headCount3
[AnimalSpecies::Pig
] == 10);
33 void TestAssignment() {
34 TestArray headCount
{8, 9, 10};
36 headCount2
= headCount
;
37 MOZ_RELEASE_ASSERT(headCount2
[AnimalSpecies::Cow
] == 8);
38 MOZ_RELEASE_ASSERT(headCount2
[AnimalSpecies::Sheep
] == 9);
39 MOZ_RELEASE_ASSERT(headCount2
[AnimalSpecies::Pig
] == 10);
43 TestInitialValueByConstructor();