mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
1dab58a2cf
This search/replace updates all copyright notices to drop the "All rights reserved", Use "ChromiumOS" instead of "Chromium OS" and drops the trailing dots. This fulfills the request from legal and unifies our notices. ./tools/health-check has been updated to only accept this style. BUG=b:246579983 TEST=./tools/health-check Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Dennis Kempin <denniskempin@google.com>
66 lines
1.8 KiB
Rust
66 lines
1.8 KiB
Rust
// Copyright 2018 The ChromiumOS Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use quote::quote;
|
|
use syn::parse_quote;
|
|
use syn::DeriveInput;
|
|
|
|
#[test]
|
|
fn test_variant_bits() {
|
|
let mut variants = vec![parse_quote!(A)];
|
|
assert_eq!(crate::variant_bits(&variants), 0);
|
|
|
|
variants.push(parse_quote!(B));
|
|
variants.push(parse_quote!(C));
|
|
assert_eq!(crate::variant_bits(&variants), 2);
|
|
|
|
for _ in 0..1021 {
|
|
variants.push(parse_quote!(Dynamic));
|
|
}
|
|
assert_eq!(crate::variant_bits(&variants), 10);
|
|
|
|
variants.push(parse_quote!(OneMore));
|
|
assert_eq!(crate::variant_bits(&variants), 11);
|
|
}
|
|
|
|
#[test]
|
|
fn event_token_e2e() {
|
|
let input: DeriveInput = parse_quote! {
|
|
enum Token {
|
|
A,
|
|
B,
|
|
C,
|
|
D(usize),
|
|
E { foobaz: u32 },
|
|
}
|
|
};
|
|
|
|
let actual = crate::event_token_inner(input);
|
|
let expected = quote! {
|
|
impl EventToken for Token {
|
|
fn as_raw_token(&self) -> u64 {
|
|
match *self {
|
|
Token::A => 0u64,
|
|
Token::B => 1u64,
|
|
Token::C => 2u64,
|
|
Token::D { 0: data } => 3u64 | ((data as u64) << 3u32),
|
|
Token::E { foobaz: data } => 4u64 | ((data as u64) << 3u32),
|
|
}
|
|
}
|
|
|
|
fn from_raw_token(data: u64) -> Self {
|
|
match data & 7u64 {
|
|
0u64 => Token::A,
|
|
1u64 => Token::B,
|
|
2u64 => Token::C,
|
|
3u64 => Token::D { 0: (data >> 3u32) as usize },
|
|
4u64 => Token::E { foobaz: (data >> 3u32) as u32 },
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
assert_eq!(actual.to_string(), expected.to_string());
|
|
}
|