| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <ostream> | 6 #include <ostream> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
| 10 #include "mojo/public/cpp/system/macros.h" | 10 #include "mojo/public/cpp/system/macros.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // Make a sample |Foo|. | 36 // Make a sample |Foo|. |
| 37 FooPtr MakeFoo() { | 37 FooPtr MakeFoo() { |
| 38 mojo::String name("foopy"); | 38 mojo::String name("foopy"); |
| 39 | 39 |
| 40 BarPtr bar(Bar::New()); | 40 BarPtr bar(Bar::New()); |
| 41 bar->alpha = 20; | 41 bar->alpha = 20; |
| 42 bar->beta = 40; | 42 bar->beta = 40; |
| 43 bar->gamma = 60; | 43 bar->gamma = 60; |
| 44 bar->type = Bar::Type::VERTICAL; | 44 bar->type = Bar::Type::VERTICAL; |
| 45 | 45 |
| 46 mojo::Array<BarPtr> extra_bars(3); | 46 auto extra_bars = mojo::Array<BarPtr>::New(3); |
| 47 for (size_t i = 0; i < extra_bars.size(); ++i) { | 47 for (size_t i = 0; i < extra_bars.size(); ++i) { |
| 48 Bar::Type type = i % 2 == 0 ? Bar::Type::VERTICAL : Bar::Type::HORIZONTAL; | 48 Bar::Type type = i % 2 == 0 ? Bar::Type::VERTICAL : Bar::Type::HORIZONTAL; |
| 49 BarPtr bar(Bar::New()); | 49 BarPtr bar(Bar::New()); |
| 50 uint8_t base = static_cast<uint8_t>(i * 100); | 50 uint8_t base = static_cast<uint8_t>(i * 100); |
| 51 bar->alpha = base; | 51 bar->alpha = base; |
| 52 bar->beta = base + 20; | 52 bar->beta = base + 20; |
| 53 bar->gamma = base + 40; | 53 bar->gamma = base + 40; |
| 54 bar->type = type; | 54 bar->type = type; |
| 55 extra_bars[i] = bar.Pass(); | 55 extra_bars[i] = bar.Pass(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 mojo::Array<uint8_t> data(10); | 58 auto data = mojo::Array<uint8_t>::New(10); |
| 59 for (size_t i = 0; i < data.size(); ++i) | 59 for (size_t i = 0; i < data.size(); ++i) |
| 60 data[i] = static_cast<uint8_t>(data.size() - i); | 60 data[i] = static_cast<uint8_t>(data.size() - i); |
| 61 | 61 |
| 62 mojo::Array<mojo::ScopedDataPipeConsumerHandle> input_streams(2); | 62 auto input_streams = mojo::Array<mojo::ScopedDataPipeConsumerHandle>::New(2); |
| 63 mojo::Array<mojo::ScopedDataPipeProducerHandle> output_streams(2); | 63 auto output_streams = mojo::Array<mojo::ScopedDataPipeProducerHandle>::New(2); |
| 64 for (size_t i = 0; i < input_streams.size(); ++i) { | 64 for (size_t i = 0; i < input_streams.size(); ++i) { |
| 65 MojoCreateDataPipeOptions options; | 65 MojoCreateDataPipeOptions options; |
| 66 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 66 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| 67 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 67 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| 68 options.element_num_bytes = 1; | 68 options.element_num_bytes = 1; |
| 69 options.capacity_num_bytes = 1024; | 69 options.capacity_num_bytes = 1024; |
| 70 mojo::ScopedDataPipeProducerHandle producer; | 70 mojo::ScopedDataPipeProducerHandle producer; |
| 71 mojo::ScopedDataPipeConsumerHandle consumer; | 71 mojo::ScopedDataPipeConsumerHandle consumer; |
| 72 mojo::CreateDataPipe(&options, &producer, &consumer); | 72 mojo::CreateDataPipe(&options, &producer, &consumer); |
| 73 input_streams[i] = consumer.Pass(); | 73 input_streams[i] = consumer.Pass(); |
| 74 output_streams[i] = producer.Pass(); | 74 output_streams[i] = producer.Pass(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 mojo::Array<mojo::Array<bool>> array_of_array_of_bools(2); | 77 auto array_of_array_of_bools = mojo::Array<mojo::Array<bool>>::New(2); |
| 78 for (size_t i = 0; i < 2; ++i) { | 78 for (size_t i = 0; i < 2; ++i) { |
| 79 mojo::Array<bool> array_of_bools(2); | 79 auto array_of_bools = mojo::Array<bool>::New(2); |
| 80 for (size_t j = 0; j < 2; ++j) | 80 for (size_t j = 0; j < 2; ++j) |
| 81 array_of_bools[j] = j; | 81 array_of_bools[j] = j; |
| 82 array_of_array_of_bools[i] = array_of_bools.Pass(); | 82 array_of_array_of_bools[i] = array_of_bools.Pass(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 mojo::MessagePipe pipe; | 85 mojo::MessagePipe pipe; |
| 86 FooPtr foo(Foo::New()); | 86 FooPtr foo(Foo::New()); |
| 87 foo->name = name; | 87 foo->name = name; |
| 88 foo->x = 1; | 88 foo->x = 1; |
| 89 foo->y = 2; | 89 foo->y = 2; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 ASSERT_FALSE(defaults->a22.is_null()); | 373 ASSERT_FALSE(defaults->a22.is_null()); |
| 374 EXPECT_EQ(imported::Shape::RECTANGLE, defaults->a22->shape); | 374 EXPECT_EQ(imported::Shape::RECTANGLE, defaults->a22->shape); |
| 375 EXPECT_EQ(imported::Color::BLACK, defaults->a22->color); | 375 EXPECT_EQ(imported::Color::BLACK, defaults->a22->color); |
| 376 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); | 376 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); |
| 377 EXPECT_EQ(0x123456789, defaults->a24); | 377 EXPECT_EQ(0x123456789, defaults->a24); |
| 378 EXPECT_EQ(-0x123456789, defaults->a25); | 378 EXPECT_EQ(-0x123456789, defaults->a25); |
| 379 } | 379 } |
| 380 | 380 |
| 381 } // namespace | 381 } // namespace |
| 382 } // namespace sample | 382 } // namespace sample |
| OLD | NEW |