1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #include "pxr/pxr.h"
26 #include "pxr/usd/usd/stage.h"
27 #include "pxr/usd/usdGeom/motionAPI.h"
28 #include "pxr/usd/usdGeom/imageable.h"
29 #include "pxr/usd/usdGeom/xform.h"
30 #include "pxr/usd/usdGeom/modelAPI.h"
31 
32 #include <iostream>
33 
34 PXR_NAMESPACE_USING_DIRECTIVE
35 
36 void
TestHasAPI()37 TestHasAPI()
38 {
39     auto stage = UsdStage::CreateInMemory("TestPrimQueries.usd");
40     auto path = SdfPath("/p");
41     auto prim = stage->DefinePrim(path);
42 
43     // Valid cases
44     TF_AXIOM(!prim.HasAPI<UsdGeomMotionAPI>());
45     TF_AXIOM(UsdGeomMotionAPI::CanApply(prim));
46     TF_AXIOM(prim.CanApplyAPI<UsdGeomMotionAPI>());
47     UsdGeomMotionAPI::Apply(prim);
48     TF_AXIOM(prim.HasAPI<UsdGeomMotionAPI>());
49     prim.RemoveAPI<UsdGeomMotionAPI>();
50     TF_AXIOM(!prim.HasAPI<UsdGeomMotionAPI>());
51     prim.ApplyAPI<UsdGeomMotionAPI>();
52     TF_AXIOM(prim.HasAPI<UsdGeomMotionAPI>());
53 
54     TF_AXIOM(!prim.HasAPI<UsdGeomModelAPI>());
55     TF_AXIOM(UsdGeomModelAPI::CanApply(prim));
56     TF_AXIOM(prim.CanApplyAPI<UsdGeomModelAPI>());
57     UsdGeomModelAPI::Apply(prim);
58     TF_AXIOM(prim.HasAPI<UsdGeomModelAPI>());
59     prim.RemoveAPI<UsdGeomModelAPI>();
60     TF_AXIOM(!prim.HasAPI<UsdGeomModelAPI>());
61     prim.ApplyAPI<UsdGeomModelAPI>();
62     TF_AXIOM(prim.HasAPI<UsdGeomModelAPI>());
63 
64     // The following cases won't compile, uncomment them to confirm
65     // TF_AXIOM(prim.HasAPI<UsdGeomImageable>()); // can't be typed
66     // TF_AXIOM(prim.HasAPI<UsdGeomXform>());     // can't be concrete
67     // TF_AXIOM(!prim.HasAPI<UsdModelAPI>());     // can't be non-applied API schema
68     //
69     // // must be derived from UsdAPISchemaBase
70     // TF_AXIOM(prim.CanApplyAPI<UsdGeomXform>());
71     // TF_AXIOM(prim.ApplyAPI<UsdGeomXform>());
72     // TF_AXIOM(prim.RemoveAPI<UsdGeomXform>());
73     //
74     // // must be multiple apply for instance name
75     // TF_AXIOM(!prim.HasAPI<UsdGeomMotionAPI>(TfToken("instance")));
76     // TF_AXIOM(prim.CanApplyAPI<UsdGeomModelAPI>(TfToken("instance")));
77     // TF_AXIOM(prim.ApplyAPI<UsdGeomModelAPI>(TfToken("instance")));
78     // TF_AXIOM(prim.RemoveAPI<UsdGeomModelAPI>(TfToken("instance")));
79 }
80 
main()81 int main()
82 {
83     TestHasAPI();
84 }
85